我试图让 Chrome pageAction 图标出现,但它只是在页面加载时短暂闪烁然后消失。
然而,让我感到困惑的是,当我使用开发工具调试器并在 chrome.pageAction.show() 调用上设置断点时,它可以完美运行!这是我的 manifest.json:
{
"manifest_version": 2,
"name": "20130409-test",
"description": "Page action icons don't work!",
"version": "0.1",
"icons": {"16": "icon16.png", "48": "icon48.png", "128": "icon128.png"},
"background": {
"scripts": ["background.js"],
"persistent": true
},
"permissions": [
"<all_urls>",
"webRequest",
"webRequestBlocking"
],
"page_action": {
"default_icon": {
"19": "icon19.png",
"38": "icon38.png"
},
"default_title": "Page action title here!"
}
}
我的 background.js 页面是:
chrome.webRequest.onSendHeaders.addListener(
function(details) {
chrome.pageAction.show(details.tabId);
chrome.pageAction.setTitle({
"tabId": details.tabId,
"title": "url=" + details.url
});
},
{urls: ["<all_urls>"], types: ["main_frame"]},
["requestHeaders"]
);