Gulli
Gulli

Reputation: 167

How to prevent Google Chrome suppressing dialogs?

How can I prevent Chrome console giving the following error when I try to use the prompt() command?

A window.prompt() dialog generated by this page was suppressed because this page is not the active tab of the front window. Please make sure your dialogs are triggered by user interactions to avoid this situation. https://www.chromestatus.com/feature/5637107137642496

Up until 2-3 days ago the prompt() command worked fine and would open a dialog where I could input data, now it always gives me this error even if I am definitely on the active tab. I have checked chrome content settings and allow popups is checked.

Thanks!

Upvotes: 7

Views: 10941

Answers (5)

mixalbl4
mixalbl4

Reputation: 3995

Call focus before window.prompt()

window.focus(); // FIX: A window.prompt() dialog generated by this page was suppressed because this page is not the active tab of the front window.

Upvotes: 1

Teddy Chen
Teddy Chen

Reputation: 11

I wrote this line in child window, then the dialog popup in child, and everything works fine.

window.opener.confirm = window.confirm;

Upvotes: 1

Abdullah Noman
Abdullah Noman

Reputation: 59

You have to dock the developer window in the same window. Don't undock into a separate window. This helped me. EDIT: Screenshot In Undocked mode That is no active window attached. And when It is docked to left || right || down the window It works Properly

Upvotes: 1

Joe Borg
Joe Borg

Reputation: 63

Basically prompt() does still work, but it either must be part of the main code (scripts preloaded onload of the web page), as otherwise if this is let's say tried from the dev tools it simply won't work - because the output will be shown in a Separate/Distinct tab than the one you're coding in (console in dev tools).

I guess this is to prevent invasive behavior that we were getting up to few years ago, where you are browsing on tab-x (eg bbc news) whilst suddenly you get focused to tab y (eg pirate site) for more clickbait, and this was all thanks to prompt and alerts.

In order to confirm or understand exactly what I'm trying to explain here, open console/dev tools on any tab you'd like to, paste in:

setTimeout (function() {
    prompt("Comprende ?")
},5000);

and after hitting return key, swiftly switch focus by clicking anywhere which doesn't redirect you to a new page on the tab you opened the devtools from, and after few seconds prompt would work.

Basically prompt before executing checks that the tab it's about to execute in, is the active focused one from the gazillion open tabs one might have.

Upvotes: 0

David
David

Reputation: 1774

The buggy behaviour here is because, when debugging using the developer tools, the developer tools window is actually the active one. A workaround is to use the play or step buttons that render over the tab that is actually being debugged, as shown below.

enter image description here

Upvotes: 3

Related Questions