w3c / webextensions

Charter and administrivia for the WebExtensions Community Group (WECG)
Other
597 stars 56 forks source link

Proposal: `browser.alert.create()` #272

Open carlosjeurissen opened 2 years ago

carlosjeurissen commented 2 years ago

Why

Since:

Resolves: https://github.com/w3c/webextensions/issues/259

Proposal

alert.create(
options // of type alert.AlertOptions
);

Which returns a promise with the returned value.

alert.AlertOptions has the following options:

To have functionality parity with confirm() and prompt(), type 'confirm' and type 'prompt' have been added. This can be dropped if not considered important.

Example

alert.create({
  type: 'prompt',
  message: 'Enter something',
}).then(function (response) {
  let userHasEntered = response;
});

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.

fregante commented 9 months 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.