Chrome扩展程序 - 选项卡切换警告

时间:2018-02-27 12:14:54

标签: javascript google-chrome

我是开发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扩展。

谢谢。

0 个答案:

没有答案