New issue
Advanced search Search tips
Starred by 32 users

Issue metadata

Status: Fixed
Closed: Aug 23

Show other hotlists

Hotlists containing this issue:

Sign in to add a comment

Issue 1500: "Could not handle JavaScript dialog" error occurs randomly when accepting confirmation dialogs.

Reported by, Sep 9 2016

Issue description

See for common issues.

Issue Description:

If I tell webdriver to dismiss a dialog, sometimes it throws an exception.

Steps to reproduce (if relevant, you MUST provide a simplified html page or
link to public site):

Tell webdriver to get this page:

<script>window.onbeforeunload = function(){ return true }</script>

Now tell webdriver to get a different page.

Catch the UnexpectedAlertPresentException

Switch to the alert and try to accept it.

Depending on the load on your computer at the time, and/or how many instances of webdriver you're trying to run concurrently, you might see this exception:

WebDriverException: Message: unknown error: unhandled inspector error: {"code":-32603,"message":"Could not handle JavaScript dialog"}
  (Session info: chrome=53.0.2785.101)
  (Driver info: chromedriver=2.23.409687 (c46e862757edc04c06b1bd88724d15a5807b84d1),platform=Linux 3.13.0-92-generic x86_64)

It seems to be raised from here:

-----Other helpful tips:
Attach your chromedriver log with verbose logging enabled (see for how to do this).

Comment 1 by, Sep 9 2016

Project Member
Status: Untriaged (was: Unconfirmed)
Issue is reproducible if we run the test in loop of more than 90 iterations in multiple threads.

  window.onbeforeunload = function(){ return true }

@Test(invocationCount=90, threadPoolSize=9)
public void test() {

System.setProperty("", "/Users/../Downloads/chromedriver");
WebDriver driver= new ChromeDriver();
catch (UnhandledAlertException e) {

Comment 2 by, Sep 9 2016

Project Member
Attaching chromedriver verbose logs, error message is at line18680.
689 KB View Download

Comment 3 by, Oct 4 2016

I have this  issue 100 % reproducing (on each test run) in the following conditions:

Host system - Windows (Intel i7, 16 GB RAM)
Guest system in VirtualBox - Linux Mint 17.1 with 2 cores, 4GB RAM (based on Ubuntu 14.04.3 LTS)
Xvfb server is started using the command:
    Xvfb :1 -screen 0 1920x986x24 -ac > /var/log/xvfb.log 2>&1 &
Chrome webdriver is started using Maven Selenium plug-in which is set up for downloading the latest driver binary available in the repository:
                                                        <!-- root directory that downloaded driver binaries will be stored in -->
                                                        <!-- Where you want to store downloaded zip files -->

Comment 4 by, Oct 7 2016

I have also seen this in the latest version, it is random

This occurs when calling Accept(), the alert is present 

 if (string.Compare(alert.Text, expectedAlert) == 0)

Test method XXX threw exception: System.InvalidOperationException: unknown error: unhandled inspector error: {"code":-32603,"message":"Could not handle JavaScript dialog"} (Session info: chrome=53.0.2785.143) (Driver info: chromedriver=2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129),platform=Windows NT 6.1.7601 SP1 x86_64)

Comment 5 by, Oct 12 2016

After moving from Chromium 51 to 52, two of our Selenium features started failing this way. I just moved from 52 to 53 and now two more Selenium features are failing. The failures are reproducible, but not deterministic. They reproduce faster when running builds in parallel (probably due to system load), but they are also reproducible when running the same feature a few times.

(Session info: chrome=53.0.2785.143)
(Driver info: chromedriver=2.24.417424 (c5c5ea873213ee72e3d0929b47482681555340c3),platform=Linux 4.4.0-38-generic x86_64)

Comment 6 by, Oct 13 2016

Project Member
 Issue 1543  has been merged into this issue.

Comment 7 by, Oct 13 2016

Project Member
 Issue 1545  has been merged into this issue.

Comment 8 by, Oct 13 2016

We didn't have this issue (and can't reproduce it) with Chromium 51.0.2704.79.

Reproducible with:
  (Session info: chrome=52.0.2743.116)
  (Driver info: chromedriver=2.22.397932 (282ed7cf89cf0053b6542e0d0f039d4123bbb6ad),platform=Linux 4.4.0-38-generic x86_64)

and also with more recent versions:
  (Session info: chrome=55.0.2877.0)
  (Driver info: chromedriver=2.24.422070,platform=Linux 4.4.0-38-generic x86_64)

When the issue occurs in our case Chromium *typically* has more than one tab open, of which one has a javascript alert. Upon manually dismissing that, it's often immediately follow by a second identical alert.

Comment 9 by, Oct 13 2016

I can build or run Chromium with more logging enabled/added and reproduce the issue if that helps. I'd need some pointers on what to enable or to log (for example in  PageHandler::HandleJavaScriptDialog) for that.

Comment 10 by, Oct 26 2016

Here's an excerpt of the logs:

[38.920][DEBUG]: DEVTOOLS EVENT Page.javascriptDialogOpening {
   "message": "true",
   "type": "beforeunload"
[38.954][DEBUG]: DEVTOOLS COMMAND Page.handleJavaScriptDialog (id=20) {
   "accept": true
[38.955][DEBUG]: DevTools request failed
[38.955][DEBUG]: DEVTOOLS RESPONSE Page.handleJavaScriptDialog (id=20) {"code":-32603,"message":"Could not handle JavaScript dialog"}

For some reason Page.handleJavaScriptDialog is returning an error even though there is a dialog open. I'm not sure if this is because the JavaScriptDialogManager is unavailable, or if the HandleJavaScriptDialog function failed.

Comment 11 by, Oct 27 2016

Also getting this error every time when running tests via TeamCity.  Get it less so when running tests manually via nunit GUI.

unknown error: unhandled inspector error: {"code":-32603,"message":"Could not handle JavaScript dialog"}
  (Session info: chrome=54.0.2840.71)
  (Driver info: chromedriver=2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed),platform=Windows NT 10.0.14393 x86_64)

Comment 12 by, Oct 27 2016

I guess we should ask someone who knows a lot about JavaScriptDialogManager, as I don't have any insights.

Comment 13 by, Nov 2 2016

+avi@, it seems that JavaScriptDialogManager::HandleJavaScriptDialog (or some subclass's version of it) is sometimes failing and returning false, even though there is a dialog showing. Do you have any ideas about what is going wrong here?

Comment 14 by, Nov 2 2016


Comment 15 by, Nov 11 2016

Also experiencing this issue. It seems it may occur more often when running headless via xvfb-run.

My setup is the following: phpunit/phpunit-selenium 3.0.2 interact with selenium-server-standalone-3.0.1.jar which is ran with xvfb-run. And then I have:

- ChromeDriver 2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e)
- Chromium 53.0.2785.143 Built on Ubuntu , running on Ubuntu 16.04

And in my phpunit tests a call to `$this->acceptAlert();` will randomly fails.

Is there any known workarounds for this ?

Comment 16 by, Nov 16 2016

Could someone give an indication if someone is working on this issue. And if so, when you think it is going to get fixed.
Or if there is one, a workaround would be nice.
Right now our builds are constantly failing and that is quite annoying to say the least.
I understand that everybody is very busy and I greatly appreciate the time you put into chrome :)

Comment 17 by, Nov 17 2016

Project Member
The following revision refers to this bug:

commit 2bc717ca99f16e07f704058c6f3faea8cfa647e9
Author: gmanikpure <>
Date: Thu Nov 17 17:46:41 2016

[chromedriver] Retry alert handling if HandleJavaScriptDialog fails.

BUG= chromedriver:1500 

Cr-Commit-Position: refs/heads/master@{#432904}


Comment 18 by, Nov 17 2016

Project Member
Labels: ChromeDriver-2.26
Status: Fixed (was: Untriaged)

Comment 19 by, Nov 18 2016

I'm happy to confirm that this solves our issue. Thank you!

Comment 20 by, Dec 5 2016

I am having the same issue with ChromeDriver 2.25. 2.26 is not released yet.
Is there a workaround I could do to get this working for timenow.

Comment 21 by, Dec 14 2016

I am still seeing the issue with chrome driver 2.26

Comment 22 by, Dec 14 2016

Please see the attached driver logs
263 KB View Download

Comment 23 by, Dec 15 2016

I can confirm also the problem persists with 2.26 although I see it less frequently now

Comment 24 by, Dec 16 2016

Project Member
sabaid.jpr@, thanks for confirming in that you no longer see the issue.

Comment 25 by, Dec 21 2016

gmanikpure, sabaid did not say the issue was fixed.  He said he had to add an arbitrary sleep step in order to avoid seeing the error.  This sounds like a flakey work-around, which indicates that the problem is definitely not fixed and they are just getting lucky.  Please re-open this and fix it for real.

Comment 26 by, Dec 22 2016

I confirm chromedriver 2.26 does NOT solve this issue.

And when examining the patch, it's no wonder it's not fixed. The patch is literally "try once, if failed re-try once". That seems way too simplistic, and I am surprised it was merged in. Was the root cause even identified ? gmanikpure can you explain the rationale behind your commit ?

Please re-open this issue.

Comment 27 by, Dec 22 2016

@adrien, @nretallack +1 the patch is definitely not a fix/solution.
@gmanikpure we are happy with the patch because our builds are a lot more stable now.
Could someone look into a proper solution?

Comment 28 by, Dec 27 2016

Project Member
Status: Assigned (was: Fixed)
Dmitry, we released a patch for retry alert handling if JavaScriptDialogManager::HandleJavaScriptDialog fails. Please see comment#17.
But looks like issue still occurs even after the retry attempt. Do you know what's going wrong here?

[12.140][INFO]: COMMAND AcceptAlert {
   "sessionId": "92ff31f41b94b531656db61c71bc2641"
[12.140][INFO]: Waiting for pending navigations...
[12.140][INFO]: Done waiting for pending navigations. Status: ok
[12.140][DEBUG]: DEVTOOLS COMMAND Page.handleJavaScriptDialog (id=366) {
   "accept": true
[12.141][DEBUG]: DEVTOOLS RESPONSE Page.handleJavaScriptDialog (id=366) {"code":-32603,"message":"Could not handle JavaScript dialog"}
[12.141][DEBUG]: DEVTOOLS COMMAND Page.handleJavaScriptDialog (id=367) {
   "accept": true
[12.142][DEBUG]: DEVTOOLS RESPONSE Page.handleJavaScriptDialog (id=367) {"code":-32603,"message":"Could not handle JavaScript dialog"}
[12.143][INFO]: RESPONSE AcceptAlert unknown error: unhandled inspector error: {"code":-32603,"message":"Could not handle JavaScript dialog"}
  (Session info: chrome=55.0.2883.87)

Comment 29 by, Jan 26 2017

Any update on this issue, interested in there progress.

Comment 30 by, Feb 13 2017

Yes, please, is there any update on this issue?
I am still stuck to ChromeDriver v2.23 and Chrome version 51.x because from ChromeDriver v2.24 and Chrome 52+ this problem occurs.

Comment 31 Deleted

Comment 32 by, Mar 2 2017

Dmitry, from bisecting, it looks like this started with r395465. Do you know what might've caused Page.handleJavaScriptDialog to become flaky?

Comment 33 by, Mar 3 2017

Could it be that we send notification early and ChromeDriver responds fast enough, so that code which handles the dialog in browser process is not yet aware of it?

Waiting a bit could help then. Also, issuing notification from the browser side (next to PageHandler::HandleJavaScriptDialog) might help as well.

Comment 34 by, Mar 10 2017

Thanks for looking into this guys. We get quite regular failures in

Session info: chrome=56.0.2924.87
Driver info: chromedriver=2.27.440174 4)

So the patch that was put in doesn't seem to have helped.

Comment 35 by, Mar 14 2017

For #c33, I'm not sure, I don't know enough about the internals to say. But Gauri did some tests earlier with adding calls to sleep (for 50 ms), and it didn't help :(

Comment 36 by, Mar 15 2017

Problem seems to be solved with chromedriver 2.28. Although my issue seemed to resemble nr 1467 as  well, which is indeed comfirmed to have been solved.

Comment 37 by, Mar 16 2017

"Could not handle JavaScript dialog" is returned by PageHandler::HandleJavaScriptDialog in the case where either there is no JavaScriptDialogManager or that calling HandleJavaScriptDialog on it fails.

It's unlikely the former, because if there were no JavaScriptDialogManager you wouldn't have been able to get a dialog in the first place.

JavaScriptDialogManager::HandleJavaScriptDialog fails if either:
- there is no active dialog, or
- it's not a JavaScript dialog (impossible nowadays; this was for dialogs from runModalDialog), or
- the active dialog belongs to a different page than the one you're calling handleJavaScriptDialog on

Hope this helps.

Comment 38 by, Mar 17 2017

The last bullet seems to match the kind of situations we run into. Beware though that we never had this issue until Chromium 52 / chromedriver 2.22.
See details in comment 8.

Comment 39 by, Mar 21 2017

Project Member
re #c33 & c#35, yesterday I performed some tests by increasing the wait time from 50ms to 1 second and it worked OK.

Comment 40 by, Mar 30 2017

I have noticed this error when the Selenium driver is at 100% CPU.  I run my test again after the CPU calms down and the error disappears.  I don't know if the high CPU is a result of the error or the other way 'round.

Comment 41 by, Apr 4 2017

Having upgraded to to 2.28 I can confirm this is till an issue

Comment 42 by, Apr 21 2017

Any more movement on this? Are we expecting a patch in the next release?

Comment 43 by, Apr 28 2017

We're having this issue too randomly on 2.28 with 10 parallel tests running. An update would be nice, this is preventing us from using chromedriver atm.

Entire environment, if necessary:
- Chrome 58
- Chromedriver 2.28
- Selenium 3.3.1
- Facebook php webdriver  1.4.0

Comment 44 by, Sep 5 2017

I upgraded Chrome and ChromeDriver to latest versions and am still getting the error and it seems even more frequently.  

Any avancement on this problem ?

unknown error: unhandled inspector error: {"code":-32000,"message":"Could not handle JavaScript dialog"}
  (Session info: chrome=60.0.3112.113)
  (Driver info: chromedriver=2.31.488763 (092de99f48a300323ecf8c2a4e2e7cab51de5ba8),platform=Windows NT 10.0.15063 x86_64)

Comment 45 by, Sep 13 2017

This is making Chrome Headless even more unstable for me than PhantomJS was

Comment 46 by, Sep 15 2017

I am running my Selenium automation test script with multiple client machine on same server. client machine having below browser version and chrome Driver:
(Session info: chrome=60.0.3112.113)
(Driver info: chromedriver=2.31.488763)
and my scripts are getting fail randomly without any fix pattern with same error :
org.openqa.selenium.WebDriverException: unknown error: unhandled inspector error: {"code":-32000,"message":"Could not handle JavaScript dialog"}

however scripts are getting pass on local re-run without any error 
Kindly suggest me the any relevant solution. 

Thanks for you help !!

Vinod Singh

Comment 47 by, Sep 18 2017

yes it's happening more often.

Do you have a plan of action and a timeline to fix this properly?, I appreciate your efforts. A proper solution is important. Therefore I think we should find the underlying cause. I have the impression that lengthening the timeout is a quick fix (how welcome it is for the short-term and hence my many thanks), but for the long term not the real solution I am afraid. 

When I do not run my tests in parallel I also do not have the problem. However the whole idea for us is to speed up the build.

Please let me know if we can help you with anything.

Comment 48 by, Sep 22 2017

Project Member

Comment 49 by, Dec 1 2017

I have the same problem when 4 parallel tests running.
- chrome=59.0.3071.115
- Chromedriver 2.30.477691

Comment 50 by, Aug 23

Project Member
Status: Fixed (was: Assigned)
This has been fixed by r491272.

Sign in to add a comment