all_frames:true不适用于stackoverflow片段输出窗口

时间:2017-09-07 01:12:37

标签: javascript iframe google-chrome-extension sandbox

我创建了一个扩展程序,我希望使用此清单注入所有框架:

"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在我使用网站时不断加载,每次我都正确地注入脚本并在代码中查看上面的行。< / p>

但是我发现了一个我无法理解的例外。如果我在StackOverflow上打开代码片段编辑器,那么iframe的结果窗格就不会被注入(即我没有在控制台中看到这些行)。

发生了什么事?我怎样才能注入片段结果窗口?

1 个答案:

答案 0 :(得分:2)

您所指的实际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

  

无法在沙盒框架中插入内容脚本。

所以,不幸的是,这将是一个你无法“闯入”的例外。