扩展中的Microsoft Edge通知 [英] Microsoft Edge notification in an extension

查看:373
本文介绍了扩展中的Microsoft Edge通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在Edge扩展中使用通知吗?

Can I use notifications in an Edge extension?

我正在将chrome扩展程序转换为Edge,此扩展程序使用通知,但在Edge中崩溃.经过一些研究,我发现Edge通知与chrome不同.因此,我创建了一个测试html页面并在IIS localhost上运行它.

I'm converting a chrome extension to Edge and this extension uses notifications but it's crashing in Edge. After some research I found Edge notifications are different from chrome. So I created a test html page and ran it on 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?

在写这些问题时我总是会忘记一些事情.

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.

总结一下,我有一个后台页面,可加载5个javaScript文件.也有一个弹出的html文件,该文件会作为用户名和密码弹出.该文件具有自己的javaScript文件,该文件可检查用户名和密码并通知结果.

To summarize this I have a background page that loads 5 javaScript files. Also have a pop up html file that pops up to as for user name and password. This file has it's own javaScript file that checks the user name and password and notifies the results.

推荐答案

您可以在Edge上使用相同的镶边通知代码.

You can use the same chrome notification code on Edge.

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

我已经做到了,而且可行.您在清单文件上拥有的API桥将负责处理此问题.

I've done it and it works. The API bridges you have on your manifest file take care of it.

但是,我无法显示通知.问题是清单上名称"属性的长度.太久了尽管它在F12工具控制台上未显示任何错误,但它的长度为41个字符,但未显示通知.我将其缩短为21个字符,并开始显示通知.更改名称后,我必须从Edge删除扩展名,然后重新安装.仅仅刷新扩展是不够的.

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. I shortened it to 21 characters and notifications started showing up. When I changed the name I had to remove the extension from Edge and then reinstall it. Simply refreshing the extension wasn't enough.

这篇关于扩展中的Microsoft Edge通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆