0

I am working on a Chrome extension, but cannot get notifications working. the workflow is the user right clicks on a link, selects "Send Link" from the extension's context menu, then a confirmation should display as a notification.

I have followed the example posted in another question, but it does not work. No notification is shown, nothing is logged in the console and the chrome.runtime.lastError is always "undefined". It's like the whole thing is just ignored. This is on Windows 10. What am I doing wrong?

script.js

  function getlink(info,tab) {
     var opt = {
        iconUrl: "http://www.google.com/favicon.ico",
        type: 'list',
        title: 'Primary Title',
        message: 'Primary message to display',
        priority: 1,
        items: [{ title: 'Item1', message: 'This is item 1.'},
                { title: 'Item2', message: 'This is item 2.'},
                { title: 'Item3', message: 'This is item 3.'}]
        };
        chrome.notifications.create('notify1', opt, function() { console.log('created!'); });
        alert(chrome.runtime.lastError);   //always undefined
  }

  chrome.contextMenus.create({
        title: "Send link", 
        contexts:["link"], 
        onclick: getlink
  });

manifest.json

{
   "manifest_version": 2,    
   "version": "1.0",               
    "name": "ext1",   
    "description": "Extension1",
    "icons": {
          "16": "images/img16.png",
          "48": "images/img48.png",
          "128": "images/img128.png"
    },
  "browser_action":
   {
          "default_icon": "images/img128.png",
          "default_popup": "popup.html"
   },
  "permissions": [
          "tabs",
          "contextMenus",
          "*://*/*",
          "notifications"
        ],
  "content_scripts": [
  {
      "matches": ["http://*/*", "https://*/*"],
      "css": ["styles.css"],
      "js": ["getDescription.js"]
  }
 ],
   "background": { 
       "scripts": ["script.js"]
   }
 }
Dave
  • 2,473
  • 2
  • 30
  • 55
  • 1) `iconUrl` can be only a local image file inside the extension directory. 2) chrome.runtime.lastError is only defined inside a callback for some `chrome` method, 3) Don't use `alert`, use devtools debugger: [Accessing console and devtools of extension's background.js](https://stackoverflow.com/a/10258029) – wOxxOm Jan 05 '21 at 21:59
  • @wOxxOm Thank you. I was able to get iconUrl to work by changing it to from http to https. For some reason it does not like http. Once I made that change the notifications started popping up as expected. Changing it to a local image in the extension directory worked as well. – Dave Jan 05 '21 at 22:24

0 Answers0