小编Coo*_*Cmd的帖子

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

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


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

manifest.json的:

"content_scripts": [{
    "matches": [ "https://www.w3.org/*" ],
    "all_frames": true,
    "js": [ "content.js" ]
}]
Run Code Online (Sandbox Code Playgroud)

content.js:

alert('content');
Run Code Online (Sandbox Code Playgroud)

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

manifest.json的:

"web_accessible_resources": ["page.html"]
Run Code Online (Sandbox Code Playgroud)

page.html中:

<!DOCTYPE html>
<iframe src="https://www.w3.org/"></iframe>
Run Code Online (Sandbox Code Playgroud)

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

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


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

javascript iframe google-chrome-extension

5
推荐指数
1
解决办法
103
查看次数