Skip to content
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
8c03f92
webview: settle a Chrome same-document navigation on its own commit
robobun Sep 10, 2026
173542e
webview: keep a page's own same-document commit out of the view's nav…
robobun Sep 10, 2026
3a1fdfe
webview: shorten the Chrome navigation comments
robobun Sep 10, 2026
ed35887
webview: one line per added comment
robobun Sep 10, 2026
fd67886
webview: require a commit of its own before a load event ends a navig…
robobun Sep 10, 2026
a6c42e5
webview: shorten the load event comment
robobun Sep 10, 2026
85fe16a
webview: match a Chrome commit to the navigation that asked for it
robobun Sep 10, 2026
068f52f
webview: one line per added comment
robobun Sep 10, 2026
4f84c59
webview: drop the Page.frameStartedNavigating classifier
robobun Sep 10, 2026
7c5b85f
webview: apply Chrome navigation events to the main frame only, with …
robobun Sep 10, 2026
299ffc8
webview: one line per added comment
robobun Sep 10, 2026
ae6e609
test(webview): drop the page-side timer and the second error page fro…
robobun Sep 10, 2026
a619cf6
webview: a Chrome reload is underway only once Chrome has answered it
robobun Sep 10, 2026
bf5865f
webview: reject a Chrome navigate() whose commit another document takes
robobun Sep 10, 2026
f94b093
docs(webview): scope the same-document navigation notes to the Chrome…
robobun Sep 10, 2026
7cc8e1a
webview: narrow the Chrome navigation change to the navigations that …
robobun Sep 11, 2026
e1e84f6
webview: a Chrome traversal ends on a same-document commit only when …
robobun Sep 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/runtime/webview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ await view.navigate("file:///path/to/index.html");

`navigate()` resolves when the main frame's `load` event fires. After it resolves, `view.url` and `view.title` reflect the new page, and `view.loading` is `false`.

A URL that only adds or changes the `#fragment` of the current page stays in the same document. The browser fires no `load` event for it, so `navigate()` resolves as soon as the new URL is current. The same applies to `goBack()` and `goForward()` over an entry of the current document, such as a `#fragment` entry or one the page made with `history.pushState()`. A `goBack()` or `goForward()` onto a page that the browser kept whole in its back-forward cache also resolves as soon as that page is current.

If the navigation fails (DNS failure, connection refused, invalid URL), the promise rejects with an `Error` describing the failure.

Only one navigation may be in flight per view at a time. Calling `navigate()` while another is pending throws `ERR_INVALID_STATE` synchronously.
Expand Down Expand Up @@ -222,7 +224,7 @@ view.onNavigationFailed = error => {
};
```

These fire **before** the corresponding `navigate()` promise settles, so by the time `await view.navigate(...)` returns, your callback has already run. Set to `null` to remove.
These fire **before** the corresponding `navigate()` promise settles, so by the time `await view.navigate(...)` returns, your callback has already run. Same-document navigations by the page (`history.pushState()`, a fragment change) also update `view.url` and fire `onNavigated`. Navigations inside an `<iframe>` do not. Set to `null` to remove.

---

Expand Down
241 changes: 190 additions & 51 deletions src/runtime/webview/ChromeBackend.cpp

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/runtime/webview/ChromeBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ struct Pending {
Method method;
PendingSlot slot;
uint32_t viewId;
// PageTitle: the JSWebView::m_chromeNavigationSeq this fetch ends, or 0 for a title refresh that settles nothing.
uint32_t navigation = 0;
};

// Transport mode. Pipe = we spawned Chrome with --remote-debugging-pipe,
Expand Down Expand Up @@ -477,6 +479,11 @@ class Transport {
void handleMessage(std::span<const char> msg);
void handleResponse(uint32_t id, std::span<const char> result, std::span<const char> error);
void handleEvent(std::span<const char> method, std::span<const char> params, std::span<const char> sessionId);
void onFrameNavigated(JSWebView*, std::span<const char> params);
void onNavigatedWithinDocument(JSWebView*, std::span<const char> params);
void onLoadEventFired(JSWebView*);
// Fetches document.title into m_title; with endsNavigation the reply also settles the Navigate slot.
void sendTitleFetch(JSWebView*, bool endsNavigation);
void rejectAllAndMarkDead(const WTF::String& reason);
void updateKeepAlive();
void writeRaw(const char* data, size_t len);
Expand Down
24 changes: 24 additions & 0 deletions src/runtime/webview/JSWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ enum class ScreenshotEncoding : uint8_t {
// bytes, return name. Not supported on Windows.
};

// Chrome: which event ends the navigation the view has in flight.
enum class ChromeNavigationKind : uint8_t {
NotRequested, // nothing asked of Chrome, or it is already done: no event ends it
Requested, // command written, no reply yet: every commit so far is the page's own
Unknown, // a history traversal, which Chrome answers with {}: the next commit of either shape ends it
SameDocument, // a #fragment or history.pushState entry: Page.navigatedWithinDocument ends it
CrossDocument, // Page.loadEventFired ends it, or the commit itself for a back-forward cache restore
};

inline const char* screenshotMimeType(ScreenshotFormat f)
{
switch (f) {
Expand Down Expand Up @@ -98,6 +107,21 @@ class JSWebView final : public WebCore::JSEventTarget {
WTF::String m_sessionId;
WTF::String m_targetId;
WTF::String m_pendingChromeNavigateUrl;
// Chrome: from the first main frame commit. Subframe events are ignored.
WTF::String m_mainFrameId;
ChromeNavigationKind m_chromeNavigationKind = ChromeNavigationKind::NotRequested;
// Chrome: a main frame document has committed since the view's last navigation command.
bool m_chromeNavigationCommitted = false;
// Chrome: the loader a Page.navigate reply named. Only its commit is that navigation's. Empty: any commit is.
WTF::String m_chromeNavigationLoaderId;
// Chrome: counts navigation commands, so a title reply settles only the navigation it was fetched for.
uint32_t m_chromeNavigationSeq = 0;
// Chrome: the live main frame document is Chrome's error page for a load that failed.
bool m_chromeOnErrorPage = false;
// Chrome: the URL whose error page committed. Reported as a failure once that page has loaded.
WTF::String m_chromeUnreportedFailure;
// Chrome: the loaderId whose failure navigate() already reported from Page.navigate's errorText.
WTF::String m_chromeFailedLoaderId;
// clickSelector stash — the actionability eval chains into a
// dispatchMouseEvent that needs these. WebViewHost has the same fields
// on its side (m_selButton etc.) for the same chain.
Expand Down
228 changes: 225 additions & 3 deletions test/js/bun/webview/fake-chrome-fixture.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading