简体   繁体   English

扩展中的Microsoft Edge通知

[英]Microsoft Edge notification in an extension

Can I use notifications in an Edge extension? 我可以在Edge扩展中使用通知吗?

I'm converting a chrome extension to Edge and this extension uses notifications but it's crashing in Edge. 我正在将chrome扩展程序转换为Edge,此扩展程序使用通知,但在Edge中崩溃。 After some research I found Edge notifications are different from chrome. 经过研究,我发现Edge通知与chrome不同。 So I created a test html page and ran it on IIS localhost. 因此,我创建了一个测试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>

Notifications worked! 通知有效! Now I tried plugging this into the extension and I don't get the permission window. 现在,我尝试将其插入扩展程序,但没有获得权限窗口。 Do you know why that's not coming up? 你知道为什么没有出现吗? Sometimes I get a message saying notifications is disabled for unknown sources. 有时,我会收到一条消息,指出未知来源的通知已禁用。 I click the button that says "turn on anyways" but notification still doesn't show up. 我单击了“始终打开”按钮,但通知仍未显示。

Are notifications blocked on all extensions or is it because I loaded this from my machine instead of the store? 通知是否在所有扩展程序上被阻止,或者是因为我是从我的计算机而不是商店加载的? When this gets delivered to the store, will the notifications work? 将其发送到商店后,通知是否有效?


Edit, Additional Information 编辑,其他信息

I always forget something when writing these questions. 在写这些问题时,我总是会忘记一些东西。

Manifest.json Manifest.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"
}
}

I tried to edit out all my company information, if I forgot any please let me know. 我试图删除我所有的公司信息,如果我忘记了任何信息,请告诉我。

To summarize this I have a background page that loads 5 javaScript files. 总结一下,我有一个后台页面,可加载5个JavaScript文件。 Also have a pop up html file that pops up to as for user name and password. 也有一个弹出的html文件,该文件会以用户名和密码的形式弹出。 This file has it's own javaScript file that checks the user name and password and notifies the results. 该文件具有其自己的javaScript文件,该文件可检查用户名和密码并通知结果。

You can use the same chrome notification code on Edge. 您可以在Edge上使用相同的Chrome通知代码。

var options = {
  "type": "basic",
  "title": "Test extension",
  "message": "Test",
  "iconUrl": "Logo.png",
  "requireInteraction": false
};
chrome.notifications.create("id1", options);

I've done it and it works. 我已经做到了,而且有效。 The API bridges you have on your manifest file take care of it. 您在清单文件上拥有的API桥会处理该问题。

However, I had trouble getting the notifications to show. 但是,我无法显示通知。 The problem was the length of the "name" attribute on the manifest. 问题是清单上“名称”属性的长度。 It was too long. 太久了 With a length of 41 characters it didn't show notifications, despite showing no error on F12 tools console. 尽管在F12工具控制台上未显示任何错误,但它的长度为41个字符,但未显示通知。 I shortened it to 21 characters and notifications started showing up. 我将其缩短为21个字符,并开始显示通知。 When I changed the name I had to remove the extension from Edge and then reinstall it. 更改名称后,我必须从Edge删除扩展名,然后重新安装。 Simply refreshing the extension wasn't enough. 仅刷新扩展是不够的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM