My manifest looks like this:
{
"manifest_version": 2,
"name": "Facebook Extension",
"version": "1.0",
"browser_action": {
"default_icon": "images/fbh.png",
"default_popup": "fbh-popup.html"
},
"permissions": [
"storage",
"background",
"tabs",
"http://www.facebook.com/*",
"https://www.facebook.com/*"
],
"content_scripts": [
{
"matches": [
"http://www.facebook.com/*",
"https://www.facebook.com/*"
],
"js": ["js/jquery-1.9.1.min.js", "js/fbh-main.js"],
"css": ["css/fbh-main.css"],
"run_at": "document_end"
}
],
"background":{
"persistent": true,
"scripts": ["js/jquery-1.9.1.min.js","js/fbh-background.js"]
}
}
I want to inject my content script each time I go to a new page within Facebook. For example, if I click on a user's profile I want to inject the content script.
In my background page I have the following listener:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo) {
console.log(changeInfo);
if (changeInfo.status === 'complete') {
chrome.tabs.executeScript(null, {file: "js/fbh-main.js"});
}
});
There are a couple of problems with this, however. First, this function tries to inject my content script into all pages. I need to be able to read the manifest permissions. Second, if I start at www.facebook.com, the content script does what it's supposed to do. But if, from there, I click the profile for "foo" and go to www.facebook.com/foo, the content script IS injected (as evidenced by a console.log message) but it does not do what it's supposed to do. I think it's being injected too soon because if I navigate directly to www.facebook.com/foo, the content script is loaded and does its thing.
Is there a better way to do this?