我尝试使用 Manifest v3 创建一个 chrome 扩展。 创建通知时,我需要设置一个 iconUrl。图标是“48.png”,它与根文件夹中的 manifest.json 一起。
我收到一个错误而不是我的通知:
Error in event handler: ReferenceError: Image is not defined
在 v3 中,他们更改了 web_accessable_resources 定义。我认为我设置错了,但也可能是其他原因..
我的 Manifest.json
{
"name": "Hello Extensions",
"description":
"Shows off desktop notifications, which are \"toast\" windows that pop up on the desktop.",
"version": "1.0",
"icons": {"16": "16.png", "48": "48.png", "128": "128.png"},
"permissions": ["alarms","storage", "notifications"],
"background": {"service_worker": "background.js"},
"manifest_version": 3,
"web_accessible_resources": [{
"resources": ["48.png"],
"matches": [],
"extension_ids": [],
"use_dynamic_url": false
}]
}
我的 background.js
chrome.runtime.onInstalled.addListener(function() {
var options = {
title: "Title",
message: "Message goes here",
type: "basic",
iconUrl: "48.png"
};
return chrome.notifications.create("", options, function() {});
});