运行tabs.executeScript时未经检查的runtime.lastError:无法访问url的内容" data:text / html,chromewebdata"

时间:2016-05-07 20:04:59

标签: google-chrome-extension

我收到此错误:

extensions::lastError:133 Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url "data:text/html,chromewebdata". Extension manifest must request permission to access this host.

我在禁用互联网后出现此错误,以便在页面加载失败(由于负载过重)或互联网停止时采取措施。

我已检查过所有类似问题并this almost similar,但仍无法使其正常工作。 Another very similar one评论说Chrome不允许劫持内部网页

我的权限如下:

"permissions": [
        "tabs","unlimitedStorage", "notifications", "history", "activeTab", "storage", "webRequest", "webRequestBlocking", "*://*/*", "http://*/*", "https://*/*"
    ],

运行此代码时出现错误:

chrome.tabs.executeScript(null, {file: "showbacklink.js"});

  chrome.tabs.executeScript(details.tabId, {file: "showbacklink.js"});

其中details.tabId是活动标签。

我缺少什么?

编辑了manifest.json

{
    "name": "",
    "options_page": "options.html",
    "description": "",
    "version": "1.0",
    "icons": {
        "16": "icons/logo16.png",
        "48": "icons/logo48.png",
        "128": "icons/logo128.png"
    },
    "permissions": [
        "tabs","unlimitedStorage", "notifications", "history", "activeTab", "storage", "webRequest", "webRequestBlocking",  "http://*/*", "https://*/*"
    ],
    "background": {
        "scripts": [
        "showbacklink.js",
            "client_server_common.js",
            "common.js",
            "background.js"

        ],
        "persistent": true
    },

    "content_security_policy": "script-src 'self'; object-src 'self'",
    "manifest_version": 2,
    "content_scripts": [
        {
            "run_at": "document_end",
            "all_frames": true,
            "matches": ["https://*/*"],
            "css": [//REMOVED],
            "js": [   //other files REMOVED
                "myscript.js",

            ]
        },


    ],
    "web_accessible_resources": [  //REMOVED
    ]


}

1 个答案:

答案 0 :(得分:2)

事实上,“离线”页面或显示的任何其他错误页面都被视为Chrome内部网页而非其“原始”网址。因此,出于安全原因,您无法注入此类页面以进行更改。想象一下,扩展程序能够与SSL警告页面进行交互 - 你真的,真的不希望这样。

如果您的目标是提供某种替代错误页面,则需要为此类导航错误挂钩侦听器并重定向到您自己的页面。

我建议您查看webNavigationwebRequest API。