无法访问url的内容

无法访问url的内容

本文介绍了chrome.tabs.executeScript出现错误“运行tabs.executeScript时未经检查的runtime.lastError:无法访问url的内容..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我试图从background.js中的外部源(如www.script.google.com)执行脚本.但是我得到这个错误-

So I am trying to execute a script from external source like www.script.google.com in background.js.But I get this error -

Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url "chrome-devtools://devtools/bundled/devtools.html?&remoteBase=https://chrome…&dockSide=undocked&toolbarColor=rgba(223,223,223,1)&textColor=rgba(0,0,0,1)". Extension manifest must request permission to access this host.

我正在做的是将消息从popup.js发送到background.js在popup.js中-

What i am doing is sending message from popup.js to background.jsIn popup.js -

 chrome.runtime.sendMessage({type:"addtask"});

在background.js中-

In background.js -

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
    if(request.type == "addtask")
    {
        chrome.tabs.executeScript(null,
                       {file:"https://script.google.com/url of script....."});
    }
});

我的manifest.json-

My manifest.json-

{
    "name": "Extension",
    "version": "0.0.1",
    "manifest_version": 2,
    "browser_action": {
        "default_popup": "popup.html"
    },
     "background": {
        "scripts": ["background.js"],
        "persistent": false
    },
    "content_scripts": [{
        "js": ["jquery.min.js","contentscript.js"],
        "matches": ["http://*/*","https://*/*"],
        "css" : ["feedback.css"]
    }],
    "permissions": [
          "storage","tabs","https://script.google.com"
        ],
    "web_accessible_resources": ["feedback.js","html2canvas.js","event.js"],
    "content_security_policy": "script-src 'self' https://script.google.com/*; object-src 'self'"
}

推荐答案

平直.将*://*/*添加到权限.

这篇关于chrome.tabs.executeScript出现错误“运行tabs.executeScript时未经检查的runtime.lastError:无法访问url的内容..."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 02:22