我可以在 Edge 扩展中使用通知吗?
我正在将 chrome 扩展程序转换为 Edge,并且此扩展程序使用通知,但它在 Edge 中崩溃。经过一番研究,我发现 Edge 通知与 chrome 不同。所以我创建了一个测试 html 页面并在 IIS localhost 上运行它。
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<title>Test Notifications</title>
</head>
<body>
<script>
if ( "Notification" in window ) {
let ask = Notification.requestPermission();
ask.then( permissions => {
if (permissions === "granted") {
let message = new Notification ("Title", { body: "Hello Nurse", icon: "icons/icon.png" });
}
});
}
</script>
<h2>Test Notifications</h2>
<p>Please turn on notifications</p>
</body>
</html>
通知有效!现在我尝试将其插入扩展程序,但我没有获得许可窗口。你知道为什么没有出现吗?有时我会收到一条消息,提示已禁用未知来源的通知。我单击显示“仍然打开”的按钮,但仍然没有显示通知。
通知是否在所有扩展程序上都被阻止,或者是因为我从我的机器而不是商店加载了它?当它被送到商店时,通知会起作用吗?
编辑,附加信息
写这些问题时,我总是忘记一些事情。
清单.json
{
"manifest_version": 2,
"name": "__MSG_extension_name__",
"version": "XXXXX",
"description": "__MSG_extension_description__",
"author": "XXXXX",
"icons": {
"16": "icons/icon16.png",
"32": "icons/icon32.png",
"48": "icons/icon48.png",
"64": "icons/icon64.png",
"128": "icons/icon.png"
},
"default_locale": "en_US",
"browser_action": {
"default_icon": {
"16": "icons/icon16.png",
"32": "icons/icon32.png",
"48": "icons/icon48.png",
"64": "icons/icon64.png",
"128": "icons/icon.png"
},
"default_title": "__MSG_extension_name__",
"default_popup": "popup.html"
},
"background": {
"page": "background.html",
"persistent": true
},
"homepage_url": "http://www.xxxxx.com/",
"inprivate": "spanning",
"minimum_edge_version": "33.14281.1000.0",
"offline_enabled": true,
"permissions": [
"<all_urls>",
"notifications",
"tabs",
"webRequest",
"webRequestBlocking",
"webNavigation",
"storage",
"unlimitedStorage",
"contextMenus"
],
"content_scripts": [
{
"css": [
"css/script.css",
"lib/jQuery-ui/jquery-ui.css"
],
"js": [
"lib/jQuery/jquery.min.js",
"lib/jQuery-ui/jquery-ui.min.js",
"js/script.min.js",
"js/xxxxx.JSInterface.Types.min.js",
"js/xxxxx.JSInterface.Utility.min.js",
"js/xxxxx.JSInterface.API.min.js",
"content_script.min.js"
],
"matches": [
"http://*/*",
"https://*/*"
],
"run_at": "document_end",
"all_frames": true
}
],
"web_accessible_resources": [
"css/script.css",
"icons/*.png",
"img/*.png",
"js/script.min.js",
"js/xxxxx.JSInterface.Types.min.js",
"js/xxxxx.JSInterface.Utility.min.js",
"js/xxxxx.JSInterface.API.min.js",
"lib/jQuery/jquery.min.js",
"lib/jQuery-ui/jquery-ui.min.js",
"lib/jQuery-ui/images/*.png",
"lib/Fancytree/dist/skin-win8/ui.fancytree.css",
"lib/Fancytree/dist/skin-win8/icons.gif",
"lib/Fancytree/dist/skin-lion/ui.fancytree.css",
"lib/Fancytree/dist/skin-lion/icons.gif",
"lib/DataTables/media/images/*.png"
],
"-ms-preload": {
"backgroundScript": "backgroundScriptsAPIBridge.js",
"contentScript": "contentScriptsAPIBridge.js"
}
}
我试图编辑我所有的公司信息,如果我忘记了请告诉我。
总而言之,我有一个加载 5 个 javaScript 文件的背景页面。还有一个弹出的html文件,弹出用户名和密码。这个文件有它自己的 javaScript 文件,它检查用户名和密码并通知结果。