Closed Bug 1918287 Opened 3 months ago Closed 3 months ago

`browsingContext.setViewport` fails intermittently with "unknown error"

Categories

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

Firefox 131
defect
Points:
2

Tracking

(firefox132 fixed)

RESOLVED FIXED
132 Branch
Tracking Status
firefox132 --- fixed

People

(Reporter: yurys, Assigned: whimboo)

References

(Blocks 2 open bugs)

Details

(Whiteboard: [webdriver:m12][webdriver:relnote])

Attachments

(3 files)

Steps to reproduce:

Run Playwright tests with Bidi Firefox as described on this page. E.g. use the following command to see the protocol log:

DEBUG=pw:protocol MAX_LOG_LENGTH=1000 npm run biditest -- --project='bidi-firefox-beta*' page-click.spec.ts:24 --workers=1 -x --repeat-each=10

Actual results:

The test is failing every other run when browsingContext.setViewport is sent with the same error response:

{"type":"error","id":14,"error":"unknown error","message":"AbortError: Actor 'MessageHandlerFrame' destroyed before query 'MessageHandlerFrameParent:sendCommand' was resolved","stacktrace":""}

Here is the protocol log:

  pw:protocol SEND ► {"id":1,"method":"session.new","params":{"capabilities":{"alwaysMatch":{"acceptInsecureCerts":false,"unhandledPromptBehavior":{"default":"ignore"},"webSocketUrl":true}}}} +0ms
  pw:protocol ◀ RECV {"type":"success","id":1,"result":{"sessionId":"3c68f635-422f-498f-b500-e42d6f465db2","capabilities":{"acceptInsecureCerts":false,"browserName":"firefox","browserVersion":"131.0","platformName":"mac","unhandledPromptBehavior":{"default":"ignore"},"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:131.0) Gecko/20100101 Firefox/131.0","moz:buildID":"20240909091655","moz:headless":true,"moz:platformVersion":"23.6.0","moz:processID":22127,"moz:profile":"/var/folders/t3/_mbh6z155sz1cr7prkpn9lsh0000gn/T/playwright_bididev_profile-X4nw8C","moz:shutdownTimeout":60000,"proxy":{}}}} +801ms
  pw:protocol SEND ► {"id":2,"method":"session.subscribe","params":{"events":["browsingContext","network","log","script"]}} +0ms
  pw:protocol ◀ RECV {"type":"event","method":"script.realmCreated","params":{"realm":"a4dec95e-a91e-4b72-8145-caca0cb6eb2a","origin":"null","context":"a3e0c04a-c8e0-4556-9691-daeae4c0092e","type":"window"}} +13ms
  pw:protocol ◀ RECV {"type":"success","id":2,"result":{}} +2ms
  pw:protocol SEND ► {"id":3,"method":"browser.createUserContext","params":{}} +8ms
  pw:protocol ◀ RECV {"type":"success","id":3,"result":{"userContext":"7a6c3aea-78b9-4783-88c9-675f562eb19d"}} +1ms
  pw:protocol SEND ► {"id":4,"method":"browsingContext.create","params":{"type":"window","userContext":"7a6c3aea-78b9-4783-88c9-675f562eb19d"}} +10ms
  pw:protocol ◀ RECV {"type":"event","method":"browsingContext.contextCreated","params":{"children":null,"context":"5ae7f48d-9a93-4dd0-a006-3d1a40abccb9","originalOpener":null,"url":"about:blank","userContext":"7a6c3aea-78b9-4783-88c9-675f562eb19d","parent":null}} +71ms
  pw:protocol SEND ► {"id":5,"method":"browsingContext.setViewport","params":{"context":"5ae7f48d-9a93-4dd0-a006-3d1a40abccb9","viewport":{"width":1280,"height":720},"devicePixelRatio":1}} +1ms
  pw:protocol ◀ RECV {"type":"event","method":"script.realmCreated","params":{"realm":"d00e0926-fe3e-4cbc-a016-cb6bb52cd264","origin":"null","context":"5ae7f48d-9a93-4dd0-a006-3d1a40abccb9","type":"window"}} +150ms
  pw:protocol SEND ► {"id":6,"method":"script.evaluate","params":{"expression":"1 + 1","target":{"context":"5ae7f48d-9a93-4dd0-a006-3d1a40abccb9","sandbox":"__playwright_utility_world__"},"serializationOptions":{"maxObjectDepth":10,"maxDomDepth":10},"awaitPromise":true,"userActivation":true}} +1ms
  pw:protocol ◀ RECV {"type":"event","method":"browsingContext.navigationStarted","params":{"context":"5ae7f48d-9a93-4dd0-a006-3d1a40abccb9","navigation":"e94153bf-de06-4063-81d4-1caecb043288","timestamp":1726101240323,"url":"about:blank"}} +5ms
  pw:protocol ◀ RECV {"type":"event","method":"script.realmCreated","params":{"realm":"924cb568-3b93-409f-8ab9-db85c4be0169","origin":"null","context":"5ae7f48d-9a93-4dd0-a006-3d1a40abccb9","type":"window","sandbox":"__playwright_utility_world__"}} +2ms
  pw:protocol ◀ RECV {"type":"success","id":6,"result":{"realm":"924cb568-3b93-409f-8ab9-db85c4be0169","type":"success","result":{"type":"number","value":2}}} +0ms
  pw:protocol ◀ RECV {"type":"event","method":"script.realmDestroyed","params":{"realm":"d00e0926-fe3e-4cbc-a016-cb6bb52cd264"}} +1ms
  pw:protocol ◀ RECV {"type":"event","method":"script.realmDestroyed","params":{"realm":"924cb568-3b93-409f-8ab9-db85c4be0169"}} +0ms
  pw:protocol ◀ RECV {"type":"error","id":5,"error":"unknown error","message":"AbortError: Actor 'MessageHandlerFrame' destroyed before query 'MessageHandlerFrameParent:sendCommand' was resolved","stacktrace":""} +0ms
  pw:protocol ◀ RECV {"type":"event","method":"script.realmCreated","params":{"realm":"c86fa192-d648-4c1f-a4e2-8a4182ed7600","origin":"null","context":"5ae7f48d-9a93-4dd0-a006-3d1a40abccb9","type":"window"}} +8ms
  pw:protocol SEND ► {"id":7,"method":"script.evaluate","params":{"expression":"1 + 1","target":{"context":"5ae7f48d-9a93-4dd0-a006-3d1a40abccb9","sandbox":"__playwright_utility_world__"},"serializationOptions":{"maxObjectDepth":10,"maxDomDepth":10},"awaitPromise":true,"userActivation":true}} +0ms
  pw:protocol ◀ RECV {"type":"event","method":"browsingContext.domContentLoaded","params":{"context":"5ae7f48d-9a93-4dd0-a006-3d1a40abccb9","timestamp":1726101240330,"url":"about:blank","navigation":"e94153bf-de06-4063-81d4-1caecb043288"}} +1ms
  pw:protocol ◀ RECV {"type":"event","method":"browsingContext.load","params":{"context":"5ae7f48d-9a93-4dd0-a006-3d1a40abccb9","timestamp":1726101240331,"url":"about:blank","navigation":"e94153bf-de06-4063-81d4-1caecb043288"}} +0ms
  pw:protocol ◀ RECV {"type":"success","id":4,"result":{"context":"5ae7f48d-9a93-4dd0-a006-3d1a40abccb9"}} +0ms
  pw:protocol ◀ RECV {"type":"event","method":"script.realmCreated","params":{"realm":"fc65d4f5-a5ac-4d12-a9c6-b612cb364a9e","origin":"null","context":"5ae7f48d-9a93-4dd0-a006-3d1a40abccb9","type":"window","sandbox":"__playwright_utility_world__"}} +4ms
  pw:protocol ◀ RECV {"type":"success","id":7,"result":{"realm":"fc65d4f5-a5ac-4d12-a9c6-b612cb364a9e","type":"success","result":{"type":"number","value":2}}} +0ms
  pw:protocol SEND ► {"id":8,"method":"browser.removeUserContext","params":{"userContext":"7a6c3aea-78b9-4783-88c9-675f562eb19d"}} +0ms
  pw:protocol ◀ RECV {"type":"success","id":8,"result":{}} +4ms
  pw:protocol ◀ RECV {"type":"event","method":"browsingContext.contextDestroyed","params":{"children":null,"context":"5ae7f48d-9a93-4dd0-a006-3d1a40abccb9","originalOpener":null,"url":"about:blank","userContext":null,"parent":null}} +5ms
  pw:protocol ◀ RECV {"type":"success","id":0,"result":{}} +5ms

Expected results:

Viewport should be updated with no errors.

Thanks for the report. As I can see the command browsingContext.create is run but it's not awaited to be completed. Instead the view port is trying to get set when the browsingContext.contextCreated event is received. But at this stage the initial about:blank page hasn't been loaded, which is causing a navigation (see the navigation events) including a replacement of the navigable (browsing context). As result the browsingContext.setViewport command fails.

Yury, are you not waiting for the command to complete on purpose? I'm asking to understand the logic and what we may have to fix here in our handling of commands. Thanks!

Flags: needinfo?(yurys)

We should likely delay sending the browsingContext.contextCreated event until the initial about:blank page has finished loading to avoid this behavior. It would also mean not sending any navigation-related events during that time. Doing so would resolve issues where clients run commands triggered by that event, but those commands fail because the navigable gets replaced.

There’s an ongoing discussion about such a topic on this GitHub issue.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Blocks: 1917540

Yury, are you not waiting for the command to complete on purpose? I'm asking to understand the logic and what we may have to fix here in our handling of commands. Thanks!

Yes, we send browsingContext.setViewport command whenever a new page is reported via browsingContext.contextCreated event. The logic is the same for the pages created by browsingContext.create and for popup pages/new tab navigations (e.g. ctrl+click). We assume that browsingContext.setViewport command can be sent at any moment regardless of the navigation state, similar to how the user can resize the browser at any time.

In the spec the viewport (and other emulation parameters) should be set on the user context level, so that there are no races with a new page starting navigation. The browser would apply all emulation parameters before the page starts navigation (be it a popup, new tab/window navigation or a page created by a Bidi client). browsingContext.setViewport command in general is only useful for emulating browser window resize.

Flags: needinfo?(yurys)

Thanks for summarizing on your side. Here's the current situation:

  1. When a new tab is opened, we're sending the browsingContext.contextCreated event too early, causing clients to assume the tab is ready for interaction. We should delay this and related events until the initial page has fully loaded (GitHub issue). I’ve also filed bug 1918672 to address this particular issue, and I believe this is likely the cause of many Playwright test failures, though I haven't run them myself yet.

  2. Instead of aborting the command when the check for re-rendered web content fails due to a browsing context replacement, we should retry the operation once the next window actor is created. The new browsing context should inherit the correct browser dimensions that were already set.

See Also: → 1854942

We probably can fix just this issue with using retryOnAbort: true when calling the _awaitViewportDimensions command in the window global here:

https://searchfox.org/mozilla-central/rev/c169f7d0287c1a6a5dd7469864135e605eed765f/remote/webdriver-bidi/modules/root/browsingContext.sys.mjs#1454-1468

This actually fixes the problem. I'll have a patch shortly.

Assignee: nobody → hskupin
Status: NEW → ASSIGNED
Severity: -- → S3
Points: --- → 2
Priority: -- → P1
Whiteboard: [webdriver:m12]

We don't depend on bug 1918672 anymore.

No longer depends on: 1918672
Attachment #9425144 - Attachment description: Bug 1918287 - [wdspec] Test for "browsingContext.setViewport" to check it's not failing on browsing context replacement. → Bug 1918287 - [wdspec] Test for "browsingContext.setViewport" to check it's not failing on browsing context creatin.
Attachment #9425144 - Attachment description: Bug 1918287 - [wdspec] Test for "browsingContext.setViewport" to check it's not failing on browsing context creatin. → Bug 1918287 - [wdspec] Test for "browsingContext.setViewport" to check it's not failing on browsing context creation.
Attachment #9425144 - Attachment description: Bug 1918287 - [wdspec] Test for "browsingContext.setViewport" to check it's not failing on browsing context creation. → Bug 1918287 - [wdspec] Test for "browsingContext.setViewport" to check it's not failing on browsing context replacement.
Pushed by hskupin@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/9aa9ab741fcb [webdriver-bidi] Retry viewport being resized check in "browsingContext.setViewport" when browsing context gets replaced. r=webdriver-reviewers,jdescottes https://hg.mozilla.org/integration/autoland/rev/29aa62e3a45f [wdspec] Test for "browsingContext.setViewport" to check it's not failing on browsing context replacement. r=webdriver-reviewers,jdescottes https://hg.mozilla.org/integration/autoland/rev/a689bca815b6 apply code formatting via Lando
Attachment #9425279 - Attachment description: Bug 1918287 - [wdspec] Fix linter failure. → Bug 1918287 - [wdspec] Fix linter failure for webdriver/bidi/browsing_context/set_viewport/viewport.py..
Pushed by smolnar@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/8e25b43c4b69 [wdspec] Fix linter failure for webdriver/bidi/browsing_context/set_viewport/viewport.py.. CLOSED TREE
Blocks: 1838663
Whiteboard: [webdriver:m12] → [webdriver:m12][webdriver:relnote]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: