我正在开发chrome扩展开发,我想构建一个扩展,它从浏览器URL地址栏和该URL的协议中捕获url。 如果访问URL协议不是https,则扩展必须显示包含某些消息的弹出窗口。我有一个下面的代码工作正常,但问题是,它点击扩展图标后显示一个弹出消息,所以我想要弹出窗口应该是当用户访问一些非https协议网址时自动显示。代码如下。
的manifest.json
{
"name": "A browser action with a popup that changes the page color",
"description": "Change the current page color",
"version": "1.0",
"permissions": [
"tabs", "http://*/*", "https://*/*","notifications","webNavigation", "*://*/*"
],
"browser_action": {
"default_title": "Set this page's color.",
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"manifest_version": 2
}
popup.js
document.addEventListener('DOMContentLoaded', function () {
chrome.tabs.query({currentWindow: true, active: true}, function(tabs){
createNotification();
});
});
function createNotification(){
var opt = {type: "basic",title: "Your Title",message: "Your message",iconUrl: "icon.png"}
chrome.notifications.create("notificationName",opt,function(){});
}