'`alert` not showing in ManifestV3 background service worker

I am trying to make a chrome extension that alerts you in the tab that you are currently moving or highlighting. I have tried reading the chrome migrating to V.3 documentation and have come up with the following code, however, the alerts never appear. Does anybody know what I need to change or add?

My 'manifest.json' file:

{
    "manifest_version": 3,
    "name": "Alert",
    "version": "0.1",
    "description": "alerts you when doing tab functions",
    "permissions": ["tabs", "activeTab"],
    "host_permissions": ["<all_urls>"],
    "background": {
        "service_worker": "background.js"
    }
}

My 'background.js' file:

chrome.tabs.onMoved.addListener(function () {
    alert("You moved this tab");
});

chrome.tabs.onHighlighted.addListener(function () {
    alert("You highlighted this tab");
});

My working directory:

.
├── background.js
├── manifest.json


Solution 1:[1]

alert is not defined in a service worker per specification so we'll have to use console.log

Also, I was looking in the wrong place for the alert messages. I needed to look at the service worker link in my unpacked extension page. enter image description here

Solution 2:[2]

alert() method cannot be used outside of the browser environment, you can use console.warn() or console.error() instead. But is not a good solution if you want to show an error message to the extension user, as they would never open the console.

If you would like a more user friendly approach use the following:

chrome.notifications.create({
type: 'basic',
iconUrl: './Images/image_if_any.png',
title: `Notification title`,
message: "Your message",
priority: 1
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 wOxxOm
Solution 2