Question

I try make deskotp notification used chrome extension. I would it can work like this - when user visit recomended page it will be show.

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"
  ]
}

any ideas why this code doesn't work? can someone give me some literature to make it proper?

Était-ce utile?

La solution

You failed to provide the proper arguments for the createNotification() function:

According to the docs:

// Create a simple text notification:
var notification = webkitNotifications.createNotification(
    '48.png',         // icon url - can be relative
    'Hello!',         // notification title
    'Lorem ipsum...'  // notification body text
);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top