This is probably me doing something dumb, but I can't figure out what. I'm trying to get a sample Google Chrome page extension demo working. The source for the demo can be found here: http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/pageAction/
It's a simple program with 2 code files - the manifest and a background.js file. Here's the background.js:
// Called when the url of a tab changes.
function checkForValidUrl(tabId, changeInfo, tab) {
// If the letter 'g' is found in the tab's URL...
if (tab.url.indexOf('g') > -1) {
// ... show the page action.
chrome.pageAction.show(tabId);
}
};
// Listen for any changes to the URL of any tab.
chrome.tabs.onUpdated.addListener(checkForValidUrl);
And here's the manifest.json file:
{
"name": "Page action by URL",
"version": "1.0",
"description": "Shows a page action for urls which have the letter 'g' in them.",
"background": { "scripts": ["background.js"] },
"page_action" :
{
"default_icon" : "icon-19.png",
"default_title" : "There's a 'G' in this URL!"
},
"permissions" : [
"tabs"
],
"icons" : {
"48" : "icon-48.png",
"128" : "icon-128.png"
},
"manifest_version": 2
}
As written, this code doesn't work for me. Chrome loads the extension just fine but when i navigate to a page with a g in the URL, no icon shows up.
I found this answer: How do I make page_action appear for specific pages?
So I tried the following-
created a background.html file :
<html><head><script> ... cut and pasted contents of background.js above </script></head></html>
changed manifest.json to have manifest_version: 1 instead of manifest_version: 2
- changed the background property in manifest.json to be background_page: "background.html"
This worked perfectly.
But I absolutely am not able to get this thing running with a background.js file and manifest_version = 2.
So I'm wondering how to get things working with manifest_version = 2 and a background.js file. Also, is this even important - i.e. is everyone just using manifest_version = 1 and not worrying about this kind of stuff?