Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
84
rated 0 times [  89] [ 5]  / answers: 1 / hits: 47973  / 10 Years ago, sun, july 6, 2014, 12:00:00

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.


More From » jquery

 Answers
78

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

[#70299] Thursday, July 3, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daryldeontaeh

Total Points: 46
Total Questions: 97
Total Answers: 105

Location: Maldives
Member since Sat, Jan 29, 2022
2 Years ago
;