1

I'm creating a chrome extension but I'm having some difficulties in use notifications webkit. When I try to display a notification, an exception is thrown:

Uncaught Error: SecurityError: DOM Exception 18

Bellow follow my Javascript code:

var icon  = 'icon_48.png';
var title = 'Test Plugin';
var body  = message;
var popup = window.webkitNotifications.createNotification(icon, title, body);
popup.show();

Bellow follow my manifest.json:

{
  "name": "Test Plugin",
  "version": "1.0.6",
  "manifest_version": 2,
  "description": "This is a test",
  "browser_action": {
    "default_icon": "images/icon_32.png",
    "default_popup": "popup.html"
  },
  "icons": {
      "128": "images/icon_128.png",
      "16": "images/icon_32.png",
      "48": "images/icon_48.png"
   },
  "permissions": [ 
    "http://*/*", 
    "https://*/*", 
    "contextMenus", 
    "tabs", 
    "notifications", 
    "management", 
    "webRequest" 
    ],
  "content_scripts": [
      {
        "matches": ["<all_urls>"],
        "js": ["webtoolkit-sha1.js","content.js"],
        "run_at": "document_end",
        "css" : ["css/style.css"]
      }
  ],
  "web_accessible_resources": ["webtoolkit-sha1.js","inject.js","icon_48.png"]
}

What am I doing wrong?

Thanks everybody!

Information Update:

manifest.json has the attribute notifications in permissions section but when I print the webkitNotifications.checkPermission() the result was 1 (PERMISSION_NOT_ALLOWED).

1 Answer 1

1

The notifications permission only applies to the extension's process. In order to get your code to work, a background (or event) page needs to be added, which creates the notification. The content script can use the messaging API to request the notification.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.