主文件
"page_action": {
"default_icon":"img/1.png",
"default_title":"Qz第一个插件",
"default_popup": "html/main.html"
},
"permissions": [
"contextMenus",
"tabs",
"notifications",
"*://*/*",
"http://*/*",
"https://*/*",
"declarativeContent"
],
修改
js
//当应用第一次安装、更新至新版本或浏览器更新至新版本时产生。
chrome.runtime.onInstalled.addListener(function() {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
// With a new rule ...
chrome.declarativeContent.onPageChanged.addRules([
{
// 注册规则,当且仅当列出的所有条件都满足时,PageStateMatcher 才会匹配网页,即当url为baidu.com ,即触发执行某个操作(目前只有 ShowPageAction)。
// That fires when a page's URL contains a 'g' ...
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlContains: 'baidu.com' },
})
],
// And shows the extension's page action.
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
});
});