在Chrome扩展程序中使用页面功能 [英] Using a page's functions in a Chrome extension

查看:120
本文介绍了在Chrome扩展程序中使用页面功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Chrome扩展程序,它将一些代码注入到网页中(我知道该部分正在工作),该代码尝试调用原始网页的一部分功能。该功能可以在控制台上正常工作,但在扩展程序调用它时会出现错误。我认为这是某种安全功能,但有没有办法避开它?请帮助!

I have a Chrome extension which is injecting some code into a web page (I know that part's working), which is trying to call a function that is part of the original web page. The function works fine from the console, but gives an error when the extension calls it. I assume this is some sort of security feature, but is there a way to get around it? Please help!

PS。它只适用于一个网站,如果有帮助的话

PS. It's just for one website, if that helps

推荐答案

你不能用内容脚本来完成它。 Chrome扩展程序内容脚本生活在孤立的世界中,这意味着它们共享DOM,但具有单独的JavaScript沙箱。阅读更多此处

You can't do it with content scripts. Chrome extensions content scripts live in isolated worlds, meaning they share DOM, but have separate JavaScript sandboxes. Read more here:

解决此问题的方法是在页面的DOM中注入< script> ,但该代码无权调用任何 chrome。* API。

The workaround to this is to inject a <script> into the DOM of the page, but that code won't have privileges to call any chrome.* APIs.

这篇关于在Chrome扩展程序中使用页面功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆