“无法访问网址内容”back.js

时间:2017-01-10 18:06:34

标签: google-chrome google-chrome-extension

我正在尝试从后台脚本调用current_script,但是我收到以下错误:

  

Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of url "chrome-devtools://devtools/bundled/inspector.html?

我知道我还需要在tab.id函数中发送executeScript,我也试过了,但没有运气。

更新:我将background.js更改为以下内容,但content_script.js仍无效:

chrome.commands.onCommand.addListener(function(command) {
  if (command === "toggle-feature") {
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
      for(var i = 0; i<tabs.length;i++) {
        alert(tabs.length);
        chrome.tabs.executeScript(tabs[i].id, {"file": "content_script.js"});
        alert("h");
      }
    });
  }
}); 

这是我的所有代码:

Manifest.nmf

{ "manifest_version": 2,
  "name": "Extractor",
  "version": "1",
  "description": "Extract from 144",
  "icons": {
    "16": "logo16.png",
    "48": "logo48.png",
    "128": "logo128.png"
  },
  "page_action": {
    "default_icon": {                    
      "16": "logo16.png",           
      "48": "logo48.png",           
      "128": "logo128.png"            
    },
    "default_title": "Extractor"          
  },
  "background": {
    "scripts": [ "background.js" ],
    "persistent": true
  },
  "content_scripts": [ {
      "matches": [ "https://www.msn.com/*" ],
      "js": [ "content_script.js" ]
  } ],
 "permissions": [
    "tabs",
    "https://www.msn.com/*",
    "activeTab",
     "*://*/*"
  ],
  "commands": {
    "toggle-feature": {
      "suggested_key": {
        "default": "Ctrl+Shift+1",
        "windows": "Ctrl+Shift+2"
      },
      "description": "Extract now"
    }
  } 
}

Background.js

chrome.commands.onCommand.addListener(function(command) {
  if (command === "toggle-feature") { 
    chrome.tabs.executeScript(null, {file: "content_script.js"} );
  }
});

content_script.js

alert("success");

如您所见,我还尝试在权限中添加所有链接组合,但没有运气!

如何在选项卡中按热键时解决此问题并使current_script工作?

0 个答案:

没有答案