2

I'm trying to work on a Chrome browser extension which does fun things on a contextmenu. The problem is, I can't get the JS files to load within the manifest.json content_scripts.

I don't receive an error, the files simply do not load.

The scripts are good, if I put them in my background page, they fire fine through that background page. The downside of that is it's restricted to only the background page.

{
"name": "Mini",
"description": "Mini", 
"permissions": ["contextMenus","management","contentSettings","tabs","http://*/*","https://*/*","editable"],
"version": "0.1",
"manifest_version": 1,
"background_page": "mini.html",
"icons" : {"16" : "mini.png"},
"contexts" : ["link","tab","page"],
"content_scripts": [{"matches":["<all_urls>"],"js":["jquery172min.js","mini.js"]}]
}

I've tried all forms of matches, including "http://\*/\*", "https://\*/\*", "\*://\*/\*"

I've tried whitespaces, no whitespaces. I'm drawing a blank here.

Any help would be appreciated.

$(document).ready(function () {
alert("page is ready");
},true); 

My apologies for that. This is a copy of the javascript/Jquery I'm using to test whether the extension has loaded or not. It's just a simple alert.

asked May 1, 2012 at 19:38

1 Answer 1

2

Content scripts cannot use the chrome.contextMenus API (in fact, these can only use some of the chrome.extension methods).

It's possible to apply match patterns to individual menu items, via chrome.contextMenus.create({title: 'Test', documentUrlPatterns: 'http://*/*'});.
Created menu items can also be modified (chrome.contextMenus.update) and removed (chrome.contextMenus.remove).

To communicate between a Content script and the background page, see Message passing.

answered May 2, 2012 at 9:10
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks! The problem right now is I can't even get to test that part out. Even should I put a simple alert which triggers on page load (via jquery) it doesn't trigger. When I look in the developer panel, no scripts are loaded for that extension.
Which dev tools? Content scripts are invisible, and can only be accessed indirectly from the background page's dev tools. Content script's console.log messages show up in the page on which it is active though.
Ok, I was talking about the developer tools that come with Chrome. So, I wouldn't see it as loaded. However, should I not see the alert trigger? I'll look into console.log. I didn't know about that one. Thanks
@MichaelLockwood I'm not a mind reader. Which alert are you talking about? Please include relevant details in your question (Use the edit link to edit the answer).
My apologies Rob. I'm trying to provide as much info as I can. However, I'm confused on this. Adding the files to the content_scripts in the Manifest.json should load those scripts in a scope which includes all tabs. Is that correct?
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.