Chrome MHTML 文件中的内容脚本注入

Chrome Content script injection in MHTML files

Chrome 似乎没有将内容脚本注入到 MHTML 类型的本地文件中。他们可能出于安全原因这样做。他们也不允许您下载扩展名为 MHTML 的文件。所以这让我很怀疑。

如果本地文件类型为 HTML,我的内容脚本将被正确注入。

这是我的清单:

"content_scripts": [
    {
        "matches": [ "http://*/*", "https://*/*", "file://*/*", "<all_urls>" ],
        "run_at": "document_start",
        "js": [
            "js/contentscript.js"
        ]
    }
],

"permissions": [ "tabs", "http://*/*", "https://*/*"],

在扩展管理页面我也查看了:

[x] Allow Access to file URLs

最后我得到的错误是:

test1.mhtml:1 Blocked script execution in 'file:///Users/test/Downloads/test1.mhtml' 
because the document's frame is sandboxed and the 'allow-scripts' permission is not set.

有没有办法解决这个问题并将我的脚本注入 .mhtl 文件?

更新: Here is a simple test extension 显示脚本注入和测试 mhtml 文件。确保在扩展管理页面中选中此复选框。 [x] 允许访问文件 URL

更新二: 找到了。这是一个 chrome 错误 https://code.google.com/p/chromium/issues/detail?id=452901

更新3: 所以看起来它可以工作,但是当文件类型为 MHTML 时,chrome 调试器不会在 UI 中显示内容脚本文件。

内容脚本通过标准声明添加,例如:

"content_scripts": [
    {
        "matches": [ "<all_urls>" ],
        "run_at": "document_end",
        "js": ["content.js"]
    }
],

备注:

  • 它不会显示在 Chrome devtools -> Sources -> Content scripts 面板中,这似乎是一个错误。
  • MHTML 有一些限制,因此某些功能可能无法使用,请在所有地方使用 console.log