w3c / webdriver-bidi

Bidirectional WebDriver protocol for browser automation
https://w3c.github.io/webdriver-bidi/
336 stars 35 forks source link

Add a browsingContext.traverseHistory command #584

Closed jgraham closed 8 months ago

jgraham commented 8 months ago

This traverses the history by a specified delta (e.g. +1 for forward, or -1 for back).

For now there is no wait parameter; the command always returns as soon as the hsitory traversal has been enqueued (this should eventually be equivalent to setting wait to none).

This model differs somewhat from the CDP model where one navigates to an explicit history entry and failure is only possible if the entry id is invalid. But back/forwward only seems closer to the use cases we have, and allowing events to be traced to a specific traversal seems consistent with the way we handle other navigation-related events.


Preview | Diff

jgraham commented 8 months ago

Note that this is an extremely basic version of the command, that skips all the issues around trying to wait for the history navigation to complete (or even to start; we currently don't return an error if you try to navigate past the last position in the session history, or before the first position).

However I think it's nearly enough for what Puppeteer does, the CDP's Page.navigateToHistoryEntry also doesn't wait or anything. The main difference is that the CDP method isn't ever called with an invalid history entry, so you know upfront if the navigation will succeed (subject to race conditions).

jgraham commented 8 months ago

I've tried to fix the error issue by pre-checking the history entry exists. That's not perfect, but I think it's good enough for now.

whimboo commented 8 months ago

FYI we will work the necessary wdspec tests when implementing this feature via https://bugzilla.mozilla.org/show_bug.cgi?id=1841018.