Is there any way to show alert from Service Worker?

2,807 views
Skip to first unread message

Shu

unread,
Oct 29, 2021, 8:26:16 AM10/29/21
to Chromium Extensions
Hello,
I hope this is my last problem :)
I am almost finished to migrate my app, but, I have a simple alert, in case user tries to use the extension on the wrong website (where I don't have access to), so I show the alert('Please, run the extension on the .... website'). Now the error is:
Error in event handler: ReferenceError: alert is not defined

Is there any simple way to show error popup when user clicks the extension icon when he shouldn't click it?

Shu

unread,
Oct 29, 2021, 8:38:06 AM10/29/21
to Chromium Extensions, Shu
P.S. I tried to do the next:
function showAlert(){
    alert('Extension works only on **.com website!');
}
chrome.scripting.executeScript({
  target: {tabId: e.id},
  function: showAlert,
});

But! Normally user install the script and try to run it in the chrome webstore to see what happens. In the past I was able to show the alert and now:
Uncaught (in promise) Error: The extensions gallery cannot be scripted.

hrg...@gmail.com

unread,
Oct 29, 2021, 12:39:12 PM10/29/21
to Chromium Extensions, Shu
That functionality is lost in MV3.
Your only choice is to open a popup window that mimics a message box.

Shu

unread,
Oct 29, 2021, 12:47:15 PM10/29/21
to Chromium Extensions, hrg...@gmail.com, Shu
Sincerely, after preparing script to mv3 I feel disappointed. I guess extension will use more resources now to work, no improvements, a lot of problems and also... Firefox still doesn't accept mv3, so I must support 2 different versions until "somewhere in 2022" other browsers will add the support for mv3.
And I already expect a lot of messages "I installed it, click on the icon and nothing happens", because they will try it in the store just after install. We can't open any popup there now..

hrg...@gmail.com

unread,
Oct 29, 2021, 1:36:24 PM10/29/21
to Chromium Extensions, Shu, hrg...@gmail.com
A popup window is not much different from an alert message box. You can give it any size and position you want and it has a title bar that looks identical to the title bar of an alert box.

There are a few disadvantages though:
1. A popup window doesn't load instantly like an alert box.
2. A popup window is not "always on top".
3. A popup window is resizable.
4. A popup window shows up in the Windows taskbar (or the corresponding list on other OSs).
5. A popup window is not synchronous like an alert box.

Reply all
Reply to author
Forward
0 new messages