Open Bug 1926855 Opened 11 days ago Updated 1 hour ago

Trying to retrieve the active window after calling "browsingContext.close" can fail due to a race condition

Categories

(Remote Protocol :: WebDriver BiDi, defect, P3)

All
Linux
defect

Tracking

(Not tracked)

People

(Reporter: whimboo, Unassigned, Mentored)

References

(Blocks 1 open bug)

Details

(Whiteboard: [lang=js])

When closing a browser window by calling the browsingContext.close command for the last remaining tab, a call to Services.focus.activeWindow afterward can return a value that is not equal to the browsing window that's open. This does only happen for some some milliseconds given that waiting a bit longer makes it return the correct value. Failures in combination with the new browser.getClientWindows command can be seen here:

https://treeherder.mozilla.org/logviewer?job_id=479529446&repo=try&lineNumber=1664-1670

[task 2024-10-23T15:52:17.722Z] 15:52:17     INFO - PID 669 | 1729698737719	RemoteAgent	DEBUG	WebDriverBiDiConnection 86bfc61f-9509-4266-aa9c-746ee49dd633 -> {"id":4,"method":"browsingContext.close","params":{"context":"a3c4d7aa-0b01-4bd5-bec2-f3b3cb46cb73"}}
[task 2024-10-23T15:52:17.722Z] 15:52:17     INFO - PID 669 | 1729698737720	RemoteAgent	TRACE	Received command browsingContext.close for destination ROOT
[task 2024-10-23T15:52:17.724Z] 15:52:17     INFO - PID 669 | 1729698737723	RemoteAgent	DEBUG	WebDriverBiDiConnection 86bfc61f-9509-4266-aa9c-746ee49dd633 <- {"type":"success","id":4,"result":{}}
[task 2024-10-23T15:52:17.735Z] 15:52:17     INFO - PID 669 | 1729698737734	RemoteAgent	TRACE	[a3c4d7aa-0b01-4bd5-bec2-f3b3cb46cb73] Navigation already marked as finished, navigationId: 032859f7-9b6e-459e-ab5d-738bff5d06bc
[task 2024-10-23T15:52:17.778Z] 15:52:17     INFO - PID 669 | 1729698737777	RemoteAgent	DEBUG	WebDriverBiDiConnection 86bfc61f-9509-4266-aa9c-746ee49dd633 -> {"id":5,"method":"browser.getClientWindows","params":{}}
[task 2024-10-23T15:52:17.779Z] 15:52:17     INFO - PID 669 | 1729698737777	RemoteAgent	TRACE	Received command browser.getClientWindows for destination ROOT
[task 2024-10-23T15:52:17.779Z] 15:52:17     INFO - PID 669 | 1729698737777	RemoteAgent	DEBUG	WebDriverBiDiConnection 86bfc61f-9509-4266-aa9c-746ee49dd633 <- {"type":"success","id":5,"result":{"clientWindows":[{"active":false,"clientWindow":"6af0e13d-abde-4d92-9c34-439598c9070f","height":600,"state":"normal","width":800,"x":100,"y":100}]}}

Waiting an extra 1s in the test makes the failures to go away:
https://treeherder.mozilla.org/jobs?repo=try&revision=46e6734187d6aa300d68196a63f7853d02f56482

As such we should probably wait when closing the window to get an activate notification on any open window, or if that cannot easily be done we maybe could check Services.focus.activeWindow directly for validity before returning.

This issue actually only happens on Linux (non Wayland) jobs.

OS: Unspecified → Linux
Hardware: Unspecified → All

Thanks @whimboo. I will pick this up

Mentor: hskupin
Severity: -- → S3
Priority: -- → P3
Whiteboard: [lang=js]
You need to log in before you can comment on or make changes to this bug.