Can a chrome extension run code on a chrome error page? (i.e. ERR_INTERNET_DISCONNECTED)

风格不统一 提交于 2020-01-01 09:34:06

问题


I am trying to create a chrome extension that runs some javascript code on the chrome error page that has the running dinosaur mini-game. I am getting a permission error when trying to run executeScript on the tab.

Here is my code:

manifest.js

{
  "manifest_version": 2,
  "name": "Extension Name",
  "description": "desc",
  "version": "1.0",
  "background": {
    "scripts": ["script.js"]
  },
  "permissions": [
    "tabs",
    "webNavigation",
    "<all_urls>"
  ]
}

script.js

chrome.webNavigation.onErrorOccurred.addListener(function (data) {
    if (data.error === "net::ERR_INTERNET_DISCONNECTED") {
        this.chrome.tabs.executeScript(data.tabId, {
            file: "execScript.js"
        });
    }
});

When I open a tab, and throttle the connection to offline using developer tools, I am redirected to the dinosaur page, but the extension complains that i must request permission to access that page:

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.
      at chrome-extension://jkjcmlcanhdodmlceikkfdklibkediio/script.js:9:26

If i try to add "data:text/html,chromewebdata" to the manifest file, it will break the extension saying that the url is invalid.

Is there a way to add a permission for that url? Is there another way to run my script on the dinosaur page?

来源:https://stackoverflow.com/questions/32761782/can-a-chrome-extension-run-code-on-a-chrome-error-page-i-e-err-internet-disco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!