【问题标题】:all_frames:true not working for stackoverflow snippet output windowall_frames:true 不适用于 stackoverflow 片段输出窗口
【发布时间】:2017-09-07 01:12:36
【问题描述】:

我创建了一个扩展,我想用这个清单注入所有帧:

"content_scripts": [
    {
        "js": ["myscript.js"],
        "matches": ["*://*/*"],
        "all_frames": true,
        "run_at": "document_start",
        "match_about_blank": true
    }
],

为了这个问题,假设myscript.js只有:

console.log('------------------------------------');
console.log(window);
console.log('------------------------------------');

当我尝试这个时,它运行良好,即如果我在 Gmail 上尝试,我可以看到许多 iframe 在我使用网站时不断加载,每次我正确注入脚本并在代码中看到上面的行。

但是我发现了一个我无法理解的异常。如果我在 StackOverflow 上打开 sn-p 编辑器,作为 iframe 的结果窗格不会被注入(即我在控制台中看不到这些行)。

发生了什么事?以及如何也注入到 sn-p 结果窗口中?

【问题讨论】:

  • 网站通常会创建一个空白的 iframe,然后用东西填充它。请参阅文档中的“match_about_blank”。
  • 谢谢!但没有没有解决它(编辑我的答案)
  • 您是否在 chrome://extensions 页面上重新加载了扩展程序?
  • 是的,我也刚刚尝试删除并重新安装它,它对你有用吗?

标签: javascript iframe google-chrome-extension sandbox


【解决方案1】:

您所指的实际iframe 具有以下形式:

<iframe      id="snpte-box-edit-result"
           name="789af52f-65c6-4c71-b52f-66063e29d6f3"
        sandbox="allow-forms allow-modals allow-scripts"
          class="snippet-box-edit"
    frameborder="0">

Content scripts documentation 引用 match_about_blank

内容脚本不能插入沙盒框架中。

因此,很遗憾,这将是一个您无法“闯入”的例外。

【讨论】:

猜你喜欢
  • 2016-06-05
  • 1970-01-01
  • 2012-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多