迁移Chrome扩展程序v3通知 [英] Migration Chrome Extension v3 Notification

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

问题描述

我正在尝试将我的Google Chrome扩展程序清单v2迁移到v3.但是尝试创建通知时出现错误.

I am trying to migrate my Google Chrome extension manifest v2 to v3. But I have an error when I try to create a notification.

服务人员错误:

extensions::imageUtil:11
Uncaught ReferenceError: Image is not defined
at loadImageData (extensions::imageUtil:11)
at Object.loadAllImages (extensions::imageUtil:74)
at replaceNotificationOptionURLs (extensions::notifications:89)
at extensions::notifications:115
at service_workers.js:2

我的service_workers.js:

My service_workers.js:

self.addEventListener('activate', (event) => {
    chrome.notifications.create({
        type:     'basic',
        iconUrl:  'assets/images/icon_128.png',
        title:    'MyTitle',
        message:  'MyMessage!'
    });
});

我的manifest.json

My manifest.json

{
 "name": "My Extension",
 "description": "...",
 "version": "0.1",
 "manifest_version": 3,
 "permissions": [
   "storage",
   "alarms",
   "notifications",
   "activeTab",
   "tabs"
 ],
 "host_permissions": [
   "http://localhost:3000/api/data"
 ],
 "background": {
   "service_worker": "service_workers.js"
 },
 "action": {
   "default_title": "ExtensionPopup",
   "default_popup": "popup/popup.html"
 },
 "icons": {
   "128": "assets/images/icon_128.png"
 },
 "content_security_policy": {
   "extension_pages": "script-src 'self'; object-src 'self' "
 }
}

我还尝试为iconUrl提供chrome.runtime.getURL或base64数据,但没有成功.我正在Chrome Canary V89上进行测试.

I also tried to provide iconUrl with chrome.runtime.getURL or base64 data, with no success. I am testing on Chrome canary V89.

我想念什么吗?预先谢谢您!

Am I missing something ? Thank you in advance !

推荐答案

根据 devlin@chromium.org .扩展通知我的通知是这样工作的,但我不知道这是否是正确的方法:

My notification works like this, but I don't know if that's the right approach:

registration.showNotification(title, {
    body: message,
    data: UUID,
    icon: logoUrl,
    message,
    actions: [
      { action: 'Open', title: 'Open' },
      { action: 'Close', title: 'Close' }
    ]
  })

self.addEventListener('notificationclick', function (event) {
  if (event.action === 'Open') {
    // something(event.notification.data) // UUID
  }
  event.notification.close()
})

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

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