0

这是一个 Chrome 扩展。

以下文档已考虑在内: Chrome Notification API

以下 3 个文件为例的问题:

显现:

{
  "name": "Title",
  "description": "desc",
  "version": "1.1",
  "manifest_version": 3,
  "background": {
    "service_worker": "bg_page.js"
  },
  "permissions": ["notifications"],
  "content_scripts": [
  {
    "matches": [
      "<all_urls>"
    ],
    "js": ["contents.js"]
  }
  ]

}

内容.js

// content.js

tld = 'com';

var url = 'https://stackoverflow.com';

console.log(url);

chrome.runtime.sendMessage({
    action: 'xhttp',
    url: url,
    tld: tld
}, function(responseText) {
    console.log(responseText);
    //handleCallback(responseText);
    //console.log(responseText);
    /*Callback function to deal with the response*/
});

bg_page.js

chrome.runtime.onMessage.addListener(function(request, sender, callback) {

    var name = 'test' + (Math.floor(Math.random() * 10000)).toString() + 'v5';

    chrome.notifications.create(name, {
        type: 'basic',
        iconUrl: 'https://i.picsum.photos/id/919/536/354.jpg?hmac=NQVTG38LLhSmuQu5ztuZ846sqRtDy4nzwI-1C457j-o',
        title: 'Test',
        message: 'Current Name: ' + name,
        priority: 2,
        }
    );
    console.log('test');

    console.log(name);

  return true;
}); 

以上适用于 Windows 上的 Chrome,但不适用于 95 版 chrome(可能还有其他版本)的 Mac。

所以我的问题是:

为什么这在装有新版 Chrome 的 Mac 上不起作用?

在此测试用例中,每次访问站点时,扩展程序都应显示桌面通知。

注意:已在 3 台单独的 Mac 上进行了测试。

它也可能不适用于旧版本,尚未经过测试,但我只关注较新版本/最新版本的 Chrome。

以下内容已经过测试和讨论:

  • Chrome 和 Mac 之间的权限问题 - 已在 3 台不同的 Mac 上进行了测试,结果均相同,但无法正常工作。
  • Chrome 和站点之间的权限问题 - 但由于它应该适用于上述测试代码中的所有站点,因此不应该是这种情况。也经过测试确认,问题依旧存在。

所以我没有想法。

4

0 回答 0