electron: Why prompt is not supported?

What is the reason that prompt is not supported?

How could input box be created? I see that prompt could be almost like confirm:

window.confirm = (message, title='') ->
  remote = require 'remote'
  dialog = remote.require 'dialog'
  buttons = ['OK', 'Cancel']
  not dialog.showMessageBox remote.getCurrentWindow(), {message, title, buttons}

Here is possible solution.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 50
  • Comments: 40 (6 by maintainers)

Commits related to this issue

Most upvoted comments

My two cents: it doesn’t make sense that Electron implements alert and confirm natively but not prompt.

There is no native prompt dialogs in most GUI toolkits, so implementing prompt in atom-shell would require writing the prompt dialog from ground up on all platforms. Due to the rare use of prompt, I think it doesn’t deserve to do all the work, and it is very easy to use a web implemented solution for this.

So I’m closing this as won’t fix.

There is no native prompt dialogs in most GUI toolkits, so implementing prompt in atom-shell would require writing the prompt dialog from ground up on all platforms.

It seems to me this going this path would make more sense than forcing every single Electron programmer to reinvent the wheel.

Same thing with alert and confirm and any dialog made with dialog api. I do not think that is a reason, sometimes this blocking is necessary (like when someone choose file to open).

It seems that on OS X at least, it can’t be that hard to support a prompt-like dialog box, since Transmission does it:

screen shot 2016-03-02 at 4 24 05 pm

I don’t get the refusal to implement this in Electron and forcing people to resort to awful hacks like this. Even if it’s not a common dialog on most operating systems, it’s still easy to fallback to the build-in prompt() dialog of Chromium, and I bet that’s all most people need. It’s basically 4 lines of clean code in Electron against pages of hacky code in clients.

The number of public repos that have had to hack around this is crazy.

While it makes sense that prompt() isn’t the most elegant way to get input from a user, it’s a non-obsolete browser API that people use frequently on their websites.

People like @beakerbrowser and @maidsafe and anyone loading webpages with Electron give the guest page most reasonable browser APIs (alert, confirm and yes even HTMLMarqueeElement works) except this one bizarre omission.

So, if only for supporting the guest content use-cases, I hope you reconsider not supporting prompt.

I made one that works just like the browser window.prompt using preload & a synchronous IPC call. Check it out here. It could use some styling, but you get the idea. (here are my changes.)

var name = prompt('What is your name?', 'David')

prompt

Prompt blocks the thread while inputting data from the user so i guess that is the main reason.

I wish prompt was implemented. I’m developing an app and want to quickly capture some input. I just want something temporary, but now I’m left looking for a workaround for something that should just be built in. No one ever really wants to use prompt, but it’s useful while developing.

Everytime I find a random, but essential, “unwilling to fix” issue in Electron, the words “Adobe Air” float through my addled brains. Let’s reinvent a broken wheel.

For anybody who really wants native prompt windows in their Electron app, I’ve written this library. It’s not perfect, but it gets the job done.

I don’t understand why prompt is not supporter and alert is ! the two block the thread and wait for a user action… As is, I think prompt is a really useful feature and it should be implemented on electron… Because now, they is no simply way to do that !!

There is no native prompt dialogs in most GUI toolkits, so implementing prompt in atom-shell would require writing the prompt dialog from ground up on all platforms. Due to the rare use of prompt, I think it doesn’t deserve to do all the work, and it is very easy to use a web implemented solution for this.

So I’m closing this as won’t fix.

The reason for closing was strange too, and it mentions atom-shell, is that how Electron was called?

But Electron is based on Chromium and I’m sure Chromium already includes code for prompt so there’s nothing to reimplement for each platform.

I think this issue, 10 years after it was created, should be reviewed again taking into account the current state of Electron.

Cannot believe this issue has been open since 2014. (Marked as closed, sure, but the problem has absolutely not been solved.)

I cannot for the life of me understand why confirm is supported but prompt is not. I don’t want to be ungrateful for the hard work you guys have put into creating this platform, but don’t you want it to be as easy to use and as valuable as possible?

2024, i still can’t understand why it’s not supported, it’s basic input! while alert/confirm are working.

Just want to add to this by saying that to me it makes no sense its not supported either.

I found this workaround https://www.npmjs.com/package/electron-prompt Not sure if its the best way to go about it

When you need a solution due to third party libraries, @konsumer’s solution works great. Great job @konsumer .

@noahbengam

No, https://github.com/jameskyburz/dialogs is a fix in response to alert, prompt, confirm not always being available.

From the readme:

Theses native counterparts block the UI thread, are are not allowed in electron and some chrome extention contexts.

This looks like a “fake” prompt in the window, but it’s a separate blocking synchronous window, just like prompt.

For anybody who really wants native prompt windows in their Electron app, I’ve written this library. It’s not perfect, but it gets the job done.

Thank you @ssight. Very well done.

Thank you @konsumer ! Still a good solution 4 years after published.

Since Dialogs are working fine and are fully customizable, I do not see why you would need prompt.

If you just want to use a shortcut, there are plenty of libs providing user inputs with JS solution and which are framework agnostics.

Enjoy Native Dialog 😃

FYI for those considering @JamesKyburz’s link, the Github page states the solution is not allowed in electron and some chrome extention contexts.

Edit: Nevermind, misread documentation. Thanks for the correction @JamesKyburz.