Chrome Web扩展程序在Firefox中运行正常,但未显示通知 [英] Chrome web extension not showing notification even though it is working fine in Firefox

查看:139
本文介绍了Chrome Web扩展程序在Firefox中运行正常,但未显示通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以简单地调用chrome.notifications.create(id,options)函数,并且已经检查了十次参数.

I have a simple call to the chrome.notifications.create(id,options) function and I have checked the arguments ten times already.

id参数是一个字符串. options参数是这样的对象:

The id argument is a string. The options argument is an object like this:

{type:"basic",message:"message",title:"message",iconUrl:chrome.extension.getURL("icons/icon.png")}

尽管它仅在Firefox中有效. Edge Opera和Chrome都无法显示该通知.边缘崩溃了!

It is only working in Firefox though. Edge Opera and Chrome all fail to display the notification. Edge just crashes!

我已经检查了所有内容.没有错误,并且iconUrl是正确的.

I've checked everything. There are no errors and the iconUrl is correct.

我还检查了清单json的名称字段.没关系. (扩展中的Microsoft Edge通知)

Also I checked the name field of the manifest json. It's fine. (Microsoft Edge notification in an extension)

示例相关的简化代码

此简化版本与完整版本存在相同的问题.

This simplified version has the same problem as the complete one.

 //For hooking up event handlers
        try {
            chrome.runtime.onStartup.addListener(doHandshake);
        }catch(ex) {
            console.error("onStartup function in Edge is not supported.");
       }
    chrome.webRequest.onBeforeRequest.addListener(onBeforeRequestCallback, { types:['main_frame'],urls:['*://*/*']}, ['blocking']);

    function onBeforeRequestCallback(requestDetails) {
        showMessage();
        return {};
    }

    function showMessage() {
        console.log("about to show notification...");
        var notificationOptions ={type:"basic",message:"msg",title:"title",iconUrl:chrome.extension.getURL("icons/icon.png")};          
        chrome.notifications.create("",notificationOptions);    
    }

manifest.json

{
  "manifest_version": 2,
  "author" : "whatever Ltd.",
  "name": "21charsName",
  "version": "1.0",
  "description": "whatever",
  "permissions": [
    "*://*/*",
    "tabs",
    "webRequest",
    "webRequestBlocking",
    "storage",
    "notifications"
  ],
  "browser_action": {
    "default_icon": "icons/icon.png",
    "default_title": "extension"
  },

  "background": {
    "scripts": [      
      "background.js"
    ],
    "persistent": true
  },
  "web_accessible_resources": []
}

推荐答案

原来,这是一个 bug 在基于铬的浏览器中. 似乎一旦禁用扩展的通知,它就永远不会再显示通知,因为无法重新启用它,并且您将不得不重新安装浏览器,尽管我的尝试也没有结果.

It turned out that it's a bug in chromium-based browsers. It seems once you disable notifications for an extension it never ever show s notifications again because there's no way to re-enable it, and you'll have to reinstall the browser, though my attempt at that yielded nothing either.

我不得不尝试另一台安装了全新Chrome浏览器的计算机,并且通知开始在该计算机上显示.

I had to try on another machine with a brand new Chrome installation and the notifications started showing on that machine.

对于Edge来说,原来是错误. :-/

As for Edge, it turned out to be a bug too. :-/

这篇关于Chrome Web扩展程序在Firefox中运行正常,但未显示通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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