Reputation: 4537
I have a simple unpacked chrome extension loaded. All other extensions turned off.
manifest.js
{
"manifest_version":2,
"name":"Etc",
"description":"Etc",
"version":"1.0",
"content_scripts": [{
"matches" : ["*://*/*"],
"js": ["contentscript.js"],
"run_at":"document_end"
}],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"permissions":[
"tabs",
"*://*/*"
],
"browser_action": {
"default_title": "Idonethis",
"default_icon":"icon.png"
}
}
The background.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.greeting == "hello")
sendResponse({farewell: "goodbye"});
});
The contentscript.js
chrome.runtime.sendMessage({greeting:"hello"}, function(response) {
console.log(response.farewell);
});
On most domains such as www.bbc.co.uk the message passing works correctly and displays
message contentscript.js:2
However on www.google.co.uk or uk.yahoo.com it does not pass a message, nor execute any contentscript.js as far as I can tell. Is this part of the security specification of chrome extensions?
EDIT This code has been fixed and can be viewed here https://github.com/lindaymacvean/test-chrome-ext
Upvotes: 0
Views: 70
Reputation: 47833
It's probably because of the match rule "matches" : ["*://*/"]
. You need to change it to "matches" : ["*://*/*"]
because currently it only matches tabs that have no path on them. E.g. http://example.com/
will match but http://example.co.uk/foo
will not match.
Upvotes: 1