我试图通过 chrome 扩展显示一个简单的桌面通知。但我保留此错误消息:
Uncaught SecurityError: An attempt was made to break through the security policy of the user agent.
这是我的清单文件:
{
"name": "My extension",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["myurl/*"],
"js": ["contentScript.js"]
}
],
"permissions": [
"notifications"
],
"web_accessible_resources": [
"chrome-logo.png"
]
}
内容脚本是:
var notification = webkitNotifications.createNotification(
'chrome-logo.png', // icon url - can be relative
'Hello!', // notification title
'Lorem ipsum...' // notification body text
);
notification.show();
我在 manifest.json 文件中添加了这一行,但这也无济于事:
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self' ",
此错误消息的解决方法是什么?