我是开发Chrome扩展程序的新手。我只是想在切换开关/窗口切换发生时提醒用户。我为所有网址制作了一个content_script。
我正在使用chrome API
chrome.tabs.query
来获取网址内容。
我的manifest.json
文件为:
{
//first three required lines
"manifest_version": 2,
"name" : "Epoch",
"version" : "1.0",
"description":"Chrome extension for alert on tab switch",
"author":"sharique",
"permissions": ["tabs"],
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["content.js"]
}
],
"browser_action":{
"default_popup":"popup.html"
}
}
content.js
如下:
chrome.windows.onFocusChanged.addListener(function() {
chrome.tabs.query({
active: true,
currentWindow: true
},
function(tabs) {
var tabURL = tabs[0].url;
var current_tab = [];
current_tab = tabURL.split('/');
alert("You are switched to : " + current_tab[2]);
});
});
popup.html
现在空白。
我读了here这个listener
存在错误。那么有没有其他方法来检测chrome中的标签更改?
Going throw chrome extension
文件非常繁忙,请在评论中提供一些方法或提供一些链接,以便我可以继续我的首次开发到chrome扩展。
谢谢。