Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: browser.alert.create() #272

Open
carlosjeurissen opened this issue Sep 15, 2022 · 1 comment
Open

Proposal: browser.alert.create() #272

carlosjeurissen opened this issue Sep 15, 2022 · 1 comment
Labels
follow-up: chrome Needs a response from a Chrome representative proposal Proposal for a change or new feature supportive: safari Supportive from Safari

Comments

@carlosjeurissen
Copy link
Contributor

carlosjeurissen commented Sep 15, 2022

Why

Since:

  • The classic alert(), prompt() and confirm() methods are not available in serviceWorkers.
  • Those methods are synchronous and pause the page
  • They do not clearly indicate their source of origin
  • They are not supported in Firefox background pages
  • Using window.create or tabs.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: #259

Proposal

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

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 dialog
  • defaultValue: optional, default value of type prompt

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.

@carlosjeurissen carlosjeurissen added agenda Discuss in future meetings proposal Proposal for a change or new feature labels Sep 15, 2022
@xeenon xeenon added the supportive: safari Supportive from Safari label Sep 15, 2022
@carlosjeurissen carlosjeurissen removed the agenda Discuss in future meetings label Sep 28, 2022
@fregante
Copy link

fregante commented Jan 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
follow-up: chrome Needs a response from a Chrome representative proposal Proposal for a change or new feature supportive: safari Supportive from Safari
Projects
None yet
Development

No branches or pull requests

4 participants