Chrome扩展程序 - 通知无效

时间:2018-03-13 05:04:05

标签: javascript html google-chrome-extension

目前正在努力制作通知但我正在努力..我已经做了很多谷歌搜索,但似乎找不到解决方案。

由于你无法在content_scripts中使用通知,我不得不尝试解决这个问题。

代码示例:

的manifest.json:

"background": {
    "scripts": ["background.js"]
},
"permissions": [
    "notifications"
],
"content_scripts": [
    {
        "matches": ["*://*/*"],
        "js": ["alert.js"]
    }
]

alert.js

window.onload = function()
{

if(document.body.innerHTML.toString().indexOf('Google') > -1 {

    alert("Hello");

    chrome.extension.sendRequest({msg: "Sup?"}, function(response) {
        console.log(response.returnMsg);
    });
}

};

background.js:

chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {

    var notify = {
        type: "basic",
        iconUrl: "icon.png",
        title: "Google",
        message: "Welcome to google",
    };

    notify.show();

    setTimeout(function(){ notify.cancel(); },5000);
    sendResponse({returnMsg: "All good!"});
}
);

0 个答案:

没有答案