Reputation: 2685
I'm creating my own extension for Google Chrome (for my own use, not to be published). At the moment I have two files:
manifest.json:
{
"manifest_version": 2,
"name": "abcdef",
"description": "abcdef",
"version": "0.1",
"permissions": [
"tabs",
"webNavigation",
"http://www.ztm.waw.pl/*"
],
"background": {
"scripts": ["bg.js"],
"persistent": false
}
}
bg.js:
chrome.webNavigation.onCompleted.addListener(function(o) {
chrome.tabs.executeScript(o.tabId, {
code: "alert('ok');"
});
}, {
url: {
hostContains: 'ztm.waw.pl'
}
});
I want the alert box to appear when I navigate to http://www.ztm.waw.pl, but it does not work. Could someone tell me why?
Upvotes: 0
Views: 3902
Reputation:
The url property of chrome.webNavigation.onCompleted accepts an array of chrome.events.UrlFilter (source), so you'll need to change your bg.js to this (note the square and curly brackets in the url property):
chrome.webNavigation.onCompleted.addListener(function(o) {
chrome.tabs.executeScript(o.tabId, {
code: "alert('ok');"
});
}, {
url: [
{hostContains: 'ztm.waw.pl'}
]
});
Upvotes: 3