【问题标题】:Content script isn't running in iframe within another extension's page内容脚本未在另一个扩展程序页面的 iframe 中运行
【发布时间】:2016-03-10 17:08:59
【问题描述】:

假设 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 issue。状态:WontFix,不幸的是。但这在未来可能会改变......

【问题讨论】:

  • 你根本做不到。扩展不能在其他扩展中运行。允许这样的事情会使恶意扩展有可能做一些非常糟糕的事情。
  • @Marc Guiselin,没有。 w3.org 不是扩展的一部分,而是在具有标准权限的自己的上下文中运行。

标签: javascript iframe google-chrome-extension


【解决方案1】:

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

【讨论】:

  • 但是,&lt;webview&gt; 仅适用于 Chrome 应用程序,不适用于扩展程序。
猜你喜欢
  • 1970-01-01
  • 2017-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-28
  • 2014-11-18
  • 2018-07-25
  • 1970-01-01
相关资源
最近更新 更多