ltr999
ltr999

Reputation: 11

Chrome Extension Notification Not working

I can't tell what's wrong with this code:

In my listener on background.js I have the following

    if (request=="notify") {
        chrome.notifications.create({title: "Title", message: "There is an time slot available", iconUrl: "icon.png",type: "basic"});;
    }

and in my content_script.js I call it using this:

    chrome.runtime.sendMessage("notify");

Notifications are enabled, but nothing is popping up. In my manifest.json I have

"permissions": [ "notifications", "tabs", "activeTab", "background" ],

Any help you can provide is much appreciated.

Upvotes: 1

Views: 1675

Answers (1)

YellowAfterlife
YellowAfterlife

Reputation: 3192

The following code in background.js

chrome.notifications.create({title: "Title", message: "There is an time slot available", iconUrl: "icon.png", type: "basic"})

with the following manifest

{
    "manifest_version": 2,

    "name": "Test",
    "description": "Hello!",
    "version": "1.0",

    "permissions": [
        "notifications", "tabs", "activeTab", "background"
    ],
    
    "background": {
        "scripts": ["background.js"]
    }
}

produces the expected result:
enter image description here

Therefore I assume your issue to be either:

  1. The image path is not valid (the notification will not show otherwise).
    You can check the console for your background script from the Extensions page: enter image description here
  2. You have at some point disabled notifications for the browser (e.g. in Settings ➜ Notifications & actions on Windows) and forgot about that.

Upvotes: 1

Related Questions