javascript - pageAction onClick no respond -
i added click event listener in working sample app (pageaction) have no idea has gone wrong. take @ 2 of file:
my manifest json
{ "name" : "page action content", "version" : "1.1", "description" : "shows page action html pages containing video", "background" : { "scripts": ["background.js"], "persistent": false }, "page_action" : { "default_icon" : "video-19.png", "default_title" : "there's <video> in page!" }, "permissions": [ "declarativecontent" ], "icons" : { "48" : "video-48.png", "128" : "video-128.png" }, "manifest_version": 2 }
background js
chrome.runtime.oninstalled.addlistener(function() { chrome.declarativecontent.onpagechanged.removerules(undefined, function() { chrome.declarativecontent.onpagechanged.addrules([{ conditions: [ // when page contains <video> tag... new chrome.declarativecontent.pagestatematcher({ css: ["video"] }) ], // ... show page action. actions: [new chrome.declarativecontent.showpageaction() ] }]); }); }); chrome.pageaction.onclicked.addlistener(function(tab) { console.log('turning ' + tab.url + ' red!'); chrome.tabs.executescript({ code: 'document.body.style.backgroundcolor="red"' }); });
i put click function within chrome.runtime, nothing happen. don't think forgot reload extension pack.
seems cannot access content of active tab, hence chrome.tabs.executescript
failed.
try acquire "activetab" permission in addition.
Comments
Post a Comment