Google chrome extension chrome.notifications.create在回调函数中不起作用

Google chrome extension chrome.notifications.create在回调函数中不起作用,google-chrome-extension,Google Chrome Extension,popup.js function start(){ let options = { type: "basic", title: "Primary Title", message: "Primary message to display", iconUrl: "/icon_128.png" } chrome.notifications.create(options); }

popup.js

function start(){
let options = {
    type: "basic",
    title: "Primary Title",
    message: "Primary message to display",
    iconUrl: "/icon_128.png"
}

chrome.notifications.create(options);
}

    // When the button is clicked, inject function will execute on current page
    startButton.addEventListener("click", async () => {
        let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
    
        chrome.scripting.executeScript({
            target: { tabId: tab.id },
            function: start,
        });
    });
manifest.json

{
    "name": "Meet Auto Exit Bot",
    "description": "Exits meet based on number of people present.",
    "version": "1.0",
    "manifest_version": 3,
    "icons": {
        "128": "icon_128.png"
    },
    "action": {
        "default_icon": "icon.png",
        "default_popup": "popup.html"
    },
    "background": {
        "service_worker": "background.js"
    },
    "permissions": [
        "storage",
        "activeTab",
        "scripting",
        "notifications"
    ]
}


我正在开发一个chrome,在其中我使用chrome通知通知用户。但我无法理解为什么
chrome.notifications.create
在我的
start()
函数中不起作用。当在回调函数外部使用时,它会工作。

控制台上有什么错误?@Robbi当我将相同的代码放在它工作的start()函数外部时,它不会显示错误1。您是在检查弹出的devTool控制台还是已经打开了service worker控制台?2.尝试在Try-catch语句中嵌入背景脚本(如果您还没有这样做的话)。Chrome91中的错误已经修复,所以请使用MV2,直到它变得稳定为止。