chrome.tabs.executeScript: Cannot access a chrome:// URL

41,955

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
}); 
Share:
41,955
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    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.