Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome.tabs.executeScript: Cannot access a chrome:// URL [duplicate]

Tags:

I am pretty new to chrome extension development.

The issue is not with accessing the chrome:// url I do not want to edit anything there, but the issue is regarding the execution of the chrome.tabs.executeScript() which is used for injection of the scripts.

I am trying to run a background script using the chrome .tabs.executeScript but it gives the following errors :


Unchecked runtime.lastError while running tabs.executeScript: Cannot access a chrome:// URL

I have the following code :

Manifest

{     "name": "BrowserExtension",     "version": "0.0.1",     "manifest_version": 2,     "description" : "Description ...",     "icons": { "16": "icons/16x16.png", "48": "icons/48x48.png", "128": "icons/128x128.png" },     "background" : {         "scripts": ["background.js"]     },           "permissions": [         "tabs",         "background",         "http://*/*",         "https://*/*"     ],     "browser_action": {         "default_icon": {             "19": "icons/19x19.png",             "38": "icons/38x38.png"         },         "default_title": "That's the tool tip"     }    } 

Background.js

console.log("background.js : click()"); chrome.tabs.executeScript(null, {file: "jquery.min.js"}, function(){     chrome.tabs.executeScript(null, {file: "auto.js"}, function(){         chrome.tabs.executeScript(null, {file: "script.js"}, function(){             //all injected         });     }); }); 

script.js

$(function() {     var input = $('input');     $.each(input,function(index,element){         var area = new AutoSuggestControl(element.id);     });          var ta = $('textarea');     $.each(ta,function(index,element){ var area = new AutoSuggestControl(element.id);});      return 1; }); 

auto.js is a precompiled js file which works perfectly fine when used alone in a html file. The aim of the extension is to provide autocomplete while writing in a textfield. Thanks a ton for helping.

like image 515
slayer Avatar asked Jul 06 '14 21:07

slayer


1 Answers

chrome:// urls are blocked for security reasons. Google doesn't want you to change the appearace or change chrome settings without the user knowing it. when you load your extension, it immediately executes those files inside the chrome://extensions page. If you want to execute your script in every tab the user goes to, you should use:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {     //code in here will run every time a user goes onto a new tab, so you can insert your scripts into every new tab });  
like image 104
Marc Guiselin Avatar answered Oct 20 '22 18:10

Marc Guiselin