假设 Google Chrome 中安装了 2 个扩展程序。
第一个扩展在 w3.org 上运行 content.js:
list .json:
"content_scripts": [{
"matches": [ "https://www.w3.org/*" ],
"all_frames": true,
"js": [ "content.js" ]
}]
content.js:
alert('content');
第二个扩展有 page.html,它将 w3.org 加载到 iframe 中:
list .json:
"web_accessible_resources": ["page.html"]
页面.html:
<!DOCTYPE html>
<iframe src="https://www.w3.org/"></iframe>
现在在地址栏输入chrome-extension://2nd-extension-id/page.html
。您将看到 w3.com,但 content.js 没有运行(没有 alert()
窗口)。我在控制台中没有看到错误。
问题是:如何允许内容脚本在这个 iframe 中运行?
我创建了 Chrome issue .状态:不幸的是,WontFix。但这在未来是可以改变的……
最佳答案
您不能使用扩展程序,但您可以在 Google Apps 中执行类似的操作:
你可以使用 webview而不是 iframe。因此,您可以通过 executeScript
方法注入(inject)脚本。
关于javascript - 内容脚本未在另一个扩展页面的 iframe 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35922904/