我的扩展程序正在使用页面操作(仅在 twitter.com 上可用),我希望在地址栏中使图标可见(并且现在至少为空),但我无法让它工作。我使用了文档三明治示例并对其进行了修改,使其看起来像这样:
内容脚本.js:
// Called when the url of a tab changes.
if(chrome.tabs.query(active(true),function{
// If the url is twitter
( {'url':'https://google.com/google-results-string'}
if (chrome.tabs.query({'url':'*://twitter.com/*'} , function(tabs){console.log(tabs)}){
// ... show the page action.
//chrome.pageAction.show(tabId);
chrome.extension.sendRequest({}, function(response) {});
}
};
// Listen for any changes to the URL of any tab.
chrome.tabs.onUpdated.addListener(checkForValidUrl);
背景.js
function onRequest(request, sender, sendResponse) {
// Show the page action for the tab that the sender (content script)
// was on.
chrome.pageAction.show(sender.tab.id);
// Return nothing to let the connection be cleaned up.
sendResponse({});
};
// Listen for the content script to send a message to the background page.
chrome.extension.onRequest.addListener(onRequest);
我不确定为什么它不起作用,我不确定如何使用 chrome.tabs.query() url 属性以及如何对照 * ://twitter.com/ * 进行检查。