1

I am trying to invoke a current_script from a background script, but I receive the following error:

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

I understand I need to send also tab.id in executeScript function, I also tried that but with no luck.

UPDATE: I changed background.js to the following but content_script.js is still not working:

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");
      }
    });
  }
}); 

Here is all my code:

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");

As you see I have also tried to add all links combinations in permissions but with no luck!

How can I solve this problem and get current_script working when pressing a hot key in a tab?

Fred Gandt
  • 4,217
  • 2
  • 33
  • 41
Tommy Kad
  • 11
  • 3
  • The error says that you're trying to inject the script into the currently active devtools window. Instead of `null` use proper `chrome.tabs.query`, this was answered here before. – wOxxOm Jan 10 '17 at 18:35
  • Hey, I just fixed it that way, but content_script is not working, I added alerts before and after executeScript and they work, but not the content_script – Tommy Kad Jan 10 '17 at 18:37
  • You may want to check the accepted solution in this related [SO post](http://stackoverflow.com/questions/36762389/chrome-extension-injecting-script-get-error). As mentioned, please try adding `"web_accessible_resources": ["content_script.js"]` in your `manifest.json`. In addition to that, [pass a parameter to a content script injected using chrome.tabs.executeScript()](http://stackoverflow.com/questions/17567624/pass-a-parameter-to-a-content-script-injected-using-chrome-tabs-executescript) might also help. – Teyam Jan 11 '17 at 11:14

0 Answers0