繁体   English   中英

内容脚本未在另一个扩展程序页面中的iframe中运行

[英]Content script isn't running in iframe within another extension's page

假设Google Chrome中安装了2个扩展程序。


第一个扩展在w3.org上运行content.js:

manifest.json的:

"content_scripts": [{
    "matches": [ "https://www.w3.org/*" ],
    "all_frames": true,
    "js": [ "content.js" ]
}]

content.js:

alert('content');

第二个扩展名有page.html,它将w3.org加载到iframe中:

manifest.json的:

"web_accessible_resources": ["page.html"]

page.html中:

<!DOCTYPE html>
<iframe src="https://www.w3.org/"></iframe>

现在输入地址栏chrome-extension://2nd-extension-id/page.html 你会看到w3.com,但是content.js没有运行(没有alert()窗口)。 我没有在控制台中看到错误。

问题是:如何允许内容脚本在此iframe中运行?


我创建了Chrome问题 状态:WontFix,不幸的是。 但是这可以在将来改变......

您不能使用扩展程序,但可以在Google Apps中执行类似操作:您可以使用webview而不是iframe。 因此,您可以通过executeScript方法注入脚本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM