Closed Bug 1663429 Opened 4 years ago Closed 4 years ago

"WebDriver:SwitchToWindow" can fail when window is closed at the same time (TypeError: can't access property "addMessageListener", this.mm is null)

Categories

(Remote Protocol :: Marionette, defect, P1)

Default
defect

Tracking

(firefox81 fixed, firefox82 fixed)

RESOLVED FIXED
82 Branch
Tracking Status
firefox81 --- fixed
firefox82 --- fixed

People

(Reporter: whimboo, Assigned: whimboo)

References

()

Details

Attachments

(1 file)

Originally filed as https://github.com/mozilla/geckodriver/issues/1770

When WebDriver:SwitchToWindow is called at the exact same time as when the target window gets closed, the following exception will be raised:

1599480854548	Marionette	DEBUG	3 -> [0,18,"WebDriver:SwitchToWindow",{"handle":"40","focus":true}]
1599480854554	Marionette	TRACE	Received DOM event TabSelect for [object XULElement]
1599480854572	Marionette	DEBUG	3 <- [1,18,{"error":"unknown error","message":"TypeError: can't access property \"addMessageListener\", this.mm is null","stacktra ... ementEventTarget@chrome://marionette/content/dom.js:46:5\nswitchToTab@chrome://marionette/content/browser.js:491:26\n"},null]
Marionette threw an error: TypeError: can't access property "addMessageListener", this.mm is null
WebElementEventTarget@chrome://marionette/content/dom.js:46:5
switchToTab@chrome://marionette/content/browser.js:491:26

The best solution here would be to move all the code in setWindowHandle() into a try/catch and raise a NoSuchWindowError instead.

There is a race condition in the "WebDriver:SwitchToWindow" command
that would throw an UnknownError instead of NoSuchWindowError when
the window gets closed at the same time as the command gets called.

Assignee: nobody → hskupin
Status: NEW → ASSIGNED

Hi Henrik. Should this bug be included as part of the Marionette MVP?

Flags: needinfo?(hskupin)
Blocks: 1623309
Flags: needinfo?(hskupin)
Priority: P3 → P1

(In reply to Marco Mucci [:MarcoM] from comment #2)

Hi Henrik. Should this bug be included as part of the Marionette MVP?

You can consider "No" when we don't set the whiteboard entry.

Pushed by hskupin@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/0bf5b58dcd64
[marionette] Only throw NoSuchWindow error in "WebDriver:SwitchToWindow". r=marionette-reviewers,jgraham
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 82 Branch

Comment on attachment 9174224 [details]
Bug 1663429 - [marionette] Only throw NoSuchWindow error in "WebDriver:SwitchToWindow".

Beta/Release Uplift Approval Request

  • User impact if declined: There is a race condition where WebDriver tests can fail if a switch to a tab happens at the same time when it gets closed. In such cases we don't return the expected error type as given by the WebDriver specification.
  • Is this code covered by automated tests?: No
  • Has the fix been verified in Nightly?: Yes
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): The code only catches further possible errors and returns the correct error type.
  • String changes made/needed: no
Attachment #9174224 - Flags: approval-mozilla-beta?

Comment on attachment 9174224 [details]
Bug 1663429 - [marionette] Only throw NoSuchWindow error in "WebDriver:SwitchToWindow".

This needs a rebased patch for Beta.

Flags: needinfo?(hskupin)
Attachment #9174224 - Flags: approval-mozilla-beta?

Comment on attachment 9174224 [details]
Bug 1663429 - [marionette] Only throw NoSuchWindow error in "WebDriver:SwitchToWindow".

Approved for 81.0b9.

Flags: needinfo?(ryanvm)
Attachment #9174224 - Flags: approval-mozilla-beta+
Product: Testing → Remote Protocol
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: