Closed Bug 1793920 Opened 2 months ago Closed 1 month ago

Don't serialize HTMLDocument as a WebElement reference


(Testing :: Marionette, defect, P1)



(firefox108 fixed)

108 Branch
Tracking Status
firefox108 --- fixed


(Reporter: whimboo, Assigned: whimboo)


(Blocks 6 open bugs)


(Whiteboard: [webdriver:m5][wptsync upstream][webdriver:relnote])


(1 file)

Whenever a WebDriver command is executed which should return a reference to the HTMLDocument it is failing with a stale element reference error. The simplest example is:

self.marionette.execute_script("return document")

That happens because our element.isStale() check has a flaw:

If el is a document then el.ownerDocument is null and we consider the element as stale. Instead of comparing the documents we should check that the element's ownerGlobal is equal to the win reference if given. Then the expected el.connected state will be returned instead.

A change here might affect a couple of currently failing tests and will make them pass.

I would like to see this bug fixed first before continuing my work on bug 1692468.

Blocks: 1764594
Blocks: 1744928
Points: --- → 2

As James mentioned to me a HTMLDocument should actually not be a WebElement because the WebDriver spec only allows Node's of type 1 to be handled as such a reference. Means when returning a document it should be handled as a basic object.

I checked the code and there is actually a bug in our isDOMElement() helper:

This code ([ELEMENT_NODE, DOCUMENT_NODE].includes(obj.nodeType)) allows both an Element and a document to be a WebElement.

Removing this we end-up in a cyclic object value and no longer raise a stale element reference when trying to return a document via Execute Script.

Summary: "evaluate.toJSON()" always raises "stale element reference" error when trying to serialize a HTMLDocument → Don't serialize HTMLDocument as a WebElement reference
Attachment #9297430 - Attachment description: Bug 1793920 - [wdspec] Don't fail with "stale element reference" error when serializing HTMLDocument. → Bug 1793920 - [wdspec] Don't serialize HTMLDocument as a WebElement reference.

The severity field is not set for this bug.
:whimboo, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(hskupin)

Note that there is the following WebDriver classic spec issue that we are waiting for a consensus first:

Severity: -- → S3
Flags: needinfo?(hskupin)
Pushed by
[wdspec] Don't serialize HTMLDocument as a WebElement reference. r=webdriver-reviewers,jgraham
Created web-platform-tests PR for changes under testing/web-platform/tests
Whiteboard: [webdriver:m5] → [webdriver:m5], [wptsync upstream]
Closed: 1 month ago
Resolution: --- → FIXED
Target Milestone: --- → 108 Branch
Upstream PR merged by moz-wptsync-bot
Whiteboard: [webdriver:m5], [wptsync upstream] → [webdriver:m5][wptsync upstream][webdriver:relnote]

We should check with consumers of Webdriver if this might cause issues once the change hits beta/release. If that's the case we will have to make modifications to the spec. See the referenced GitHub issue for that.

You need to log in before you can comment on or make changes to this bug.