0
我尝试使用desktop扩展通知使用扩展名。 我会这样工作 - 当用户访问建议的页面时,它会显示。带扩展卡的Chrome扩展通知
background.js
function show() {
var notification = window.webkitNotifications.createNotification(
'48.png',
'YOUR VISIT PAGE http://stackoverflow.com/!'
);
notification.show();
}
// Conditionally initialize the options.
if (!localStorage.isInitialized) {
localStorage.isActivated = true; // The display activation.
localStorage.frequency = 1; // The display frequency, in minutes.
localStorage.isInitialized = true; // The option initialization.
}
function checkForValidUrl(tabId, changeInfo, tab) {
if (tab.url.indexOf('stackoverflow') > -1) {
if (window.webkitNotifications) {
if (JSON.parse(localStorage.isActivated)) {
show();
}
}
}
}
chrome.tabs.onUpdated.addListener(checkForValidUrl);
manifest.json的
{
"name": "YouVisit",
"version": "0.1",
"description":
"Show desktop notification when user visit page",
"icons": {"48": "48.png"},
"permissions": [
"notifications",
"tabs"
],
"background": { "scripts": ["background.js"] },
"manifest_version": 2,
"web_accessible_resources": [
"48.png"
]
}
任何想法,为什么这个代码不工作?有人能给我一些文学作品吗?
什么它不工作?你需要包含错误细节。 – abraham
您应该使用[chrome.storage.sync](https://developer.chrome.com/extensions/storage)而不是localStorage,并考虑使用[Chrome扩展程序通知](https://developer.chrome.com/扩展/通知)(其中[不需要任何特殊许可](https://developer.chrome.com/extensions/permission_warnings#nowarning))而不是webkitNotifications(这需要用户授予权限)。 –