Reputation: 1331
I was trying out to display a simple desktop notification thru chrome extensions. But I keep this error message:
Uncaught SecurityError: An attempt was made to break through the security policy of the user agent.
This is my manifest file:
{
"name": "My extension",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["myurl/*"],
"js": ["contentScript.js"]
}
],
"permissions": [
"notifications"
],
"web_accessible_resources": [
"chrome-logo.png"
]
}
the content script is :
var notification = webkitNotifications.createNotification(
'chrome-logo.png', // icon url - can be relative
'Hello!', // notification title
'Lorem ipsum...' // notification body text
);
notification.show();
I added this line in the manifest.json file, but that didn't help either:
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self' ",
what is the work around for this error message?
Upvotes: 0
Views: 1961
Reputation: 14657
You are trying to use the webkitNotifications api, which requires that the user gives previous consent to display notifications.
From an extension you can use the chrome.notifications api instead, but you need to do it from the background page, not from a content script. If you need to display a notification based on something that happens on a webpage, you can send a message from a content script to your background page telling it to display the notification.
Upvotes: 2