我的扩展使用的是页面动作(仅在twitter.com上可用),我希望在地址栏中显示图标(并且至少功能至少为空),但是我无法让它工作。 我用documentation sandwich sample和修改它,所以它看起来是这样的:检查当前标签对字符串
contentscript.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);
background.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/ *来检查它。
你的JavaScript语法是无效的。为什么添加jQuery标签? 'onRequest'已被弃用,使用'chrome.extension.onMessage' /'sendMessage',甚至是更新的'chrome.runtime.onMessage' /'sendMessage'。 – 2013-04-09 09:02:46
我是Chrome扩展的初学者。感谢您注意到我的标签,我将删除它。 – Edeph 2013-04-09 09:06:04