Open carlosjeurissen opened 2 years ago
It's not my favorite API, but I found that chrome.offscreen
can do this already. I wrote about it here:
Alternatively, opening a window might work, but it requires a bit of (styling) work. I wrapped it up and published it as https://github.com/fregante/webext-alert
More information can be found in my previous issue, now folded into your proposal.
Why
Since:
alert()
,prompt()
andconfirm()
methods are not available inserviceWorkers
.window.create
ortabs.create
adds a lot of boilerplate to extensions code are not very suitable for small alerts especially on mobile due to the lack of windows .Resolves: https://github.com/w3c/webextensions/issues/259
Proposal
Which returns a promise with the returned value.
alert.AlertOptions
has the following options:type
: optional, either one of 'alert', 'confirm', 'prompt'. default: 'alert'title
: optional, title of the alert (addition on top of the classic methods)message
: body text of the dialogdefaultValue
: optional, default value of typeprompt
To have functionality parity with
confirm()
andprompt()
, type 'confirm' and type 'prompt' have been added. This can be dropped if not considered important.Example
Potential designs
How this will look for the end user can be different across browsers and operating systems. On desktop for example, one can consider a dialog window coming from the extension icon (if present). On mobile, it can be a dialog in the middle of the screen, which clearly shows the extension icon next to it to know its source of origin.
Security considerations
If an alert is already being displayed, calling
i18n.alert.create
will reject its returned promise.If many alerts are opened in a short time-frame, browsers can consider a 'do not show again' checkbox just like the classic
window.alert()
API does.