Repository navigation
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughWebView navigation methods accept optional waitUntil and timeout options; lifecycle events (DOMContentLoaded or load) drive promise settlement, parent-side timeouts can reject navigations, and Chrome backend matches lifecycle events to committed frame/loader IDs. ChangesWebView Navigation with waitUntil and Timeout Support
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Full details: Description checkExplanation The description explains the problem, implementation, backend differences, timeout behavior, tests, verification results, and deferred issues. It does not use the exact template headings, but it provides the required information and is substantially complete. Comment |
|
Updated 7:28 PM PT - Sep 1st, 2026
✅ @robobun, your commit 3ad225378c07995dd376e62f8d32f1dd3f3d2079 passed in 🧪 To try this PR locally: bunx bun-pr 30645That installs a local version of the PR into your bun-30645 --bun |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/runtime/webview/JSWebView.cpp`:
- Around line 320-359: The comment says timeouts are armed for symmetry but in
JSWebView::goBack, JSWebView::goForward, and JSWebView::reload the WK_DISPATCH
path returns directly so armNavTimeout(g, timeoutMs) is never called; either
update the comment to state WebKit doesn't arm the timeout, or change the
WK_DISPATCH branches to mirror navigate by saving the promise, calling
armNavTimeout(g, timeoutMs), then returning that promise (i.e., follow
navigate's pattern) so behavior matches the comment; reference the WK_DISPATCH
macro, armNavTimeout, and the navigate implementation when making the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 82a744d8-3bde-42f2-ae9d-10dca0d6447d
📒 Files selected for processing (8)
packages/bun-types/bun.d.tssrc/runtime/webview/ChromeBackend.cppsrc/runtime/webview/JSWebView.cppsrc/runtime/webview/JSWebView.hsrc/runtime/webview/JSWebViewConstructor.cppsrc/runtime/webview/JSWebViewPrototype.cpptest/js/bun/webview/webview-chrome.test.tstest/js/bun/webview/webview-navigate-options.test.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/runtime/webview/JSWebViewPrototype.cpp`:
- Around line 243-255: The code currently coerces non-number JS values for
options.timeout via toNumber(); change it to reject any non-number (except
undefined) the same way waitUntil does: after retrieving t (from o->get(...,
"timeout")), if t.isUndefined() skip, otherwise require t.isNumber() and if not
call Bun::ERR::INVALID_ARG_VALUE (using "options.timeout"_s and t) and return
false; then call t.toNumber(g), check RETURN_IF_EXCEPTION, validate finiteness
and non-negativity, and clamp into timeout as before.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 5a93f631-b47b-421c-b2f8-d91884de81cd
📒 Files selected for processing (6)
packages/bun-types/bun.d.tssrc/runtime/webview/ChromeBackend.cppsrc/runtime/webview/JSWebView.cppsrc/runtime/webview/JSWebViewConstructor.cppsrc/runtime/webview/JSWebViewPrototype.cpptest/js/bun/webview/webview-navigate-options.test.ts
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/runtime/webview/ChromeBackend.cpp`:
- Around line 1204-1206: The branch handling the "Page.loadEventFired" event
must not clear view->m_loading for a stale/cleared loader; modify the check so
m_loading is only set to false when the current loader is still active (e.g.,
require that view->m_loaderId is non-empty or otherwise matches the event's
loader id) before clearing m_loading and calling chainTitle; update the
Page.loadEventFired handling in ChromeBackend.cpp to gate setting
view->m_loading = false behind the loader-id validity check (and then call
chainTitle() only as before when view->m_pendingNavigate is true).
In `@src/runtime/webview/JSWebView.cpp`:
- Around line 348-377: The Chrome branches for JSWebView::reload and
JSWebView::goBack/JSWebView::goForward must set the view loading flag the same
way navigate() does: set m_loading (or call the same setter navigate() uses) to
true when beginning a Chrome navigation (i.e. before calling
CDP::Ops::reload/goBack/goForward and before armNavTimeout), and for the
history-path that queries Page.getNavigationHistory ensure you set m_loading =
true when the history response confirms there is an entry to traverse to; this
will keep view.loading in sync with in-flight Chrome reload/history navigations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 5482aa6a-e445-4dee-a7d2-5086baecfde9
📒 Files selected for processing (4)
src/runtime/webview/ChromeBackend.cppsrc/runtime/webview/JSWebView.cppsrc/runtime/webview/JSWebViewConstructor.cpptest/js/bun/webview/webview-navigate-options.test.ts
Status: reopened 2026-09-02, rebased onto main, waiting on CI and a maintainerThe stale bot closed this PR after 90 days without a maintainer response. Reopened, squashed, and rebased onto Reproduction
Rebase notes
PR: #30645 |
16c6719 to
3534b57
Compare
|
Closing this PR because it has been inactive for more than 90 days. |
`waitUntil: "load" | "domcontentloaded"` (default "load") picks the milestone that settles the returned promise. `timeout` (default 30000 ms, 0 disables it) rejects the promise with "Navigation timeout of <n>ms exceeded". Chrome backend: Page.setLifecycleEventsEnabled is sent once per session. Page.lifecycleEvent settles a "domcontentloaded" wait when the main frame's loaderId (captured from Page.frameNavigated) reaches DOMContentLoaded or load. Page.loadEventFired keeps settling "load". A generation counter on the view invalidates the timeout timer once the Navigate slot settles, including the close() path through rejectSlotAsHandled. Every Navigate-slot CDP response carries the generation it was sent under, so a reply for a timed-out navigation cannot settle a later retry; a stale Target.createTarget reply closes the tab it created. WebKit backend: accepts the options. "domcontentloaded" behaves like "load" (no separate delegate hook). The timeout applies. Types: add WebView.NavigateOptions. Rename back()/forward() to the runtime's goBack()/goForward().
There was a problem hiding this comment.
Additional findings (outside the current diff — GitHub can't attach inline comments there):
-
🔴
src/runtime/webview/ChromeBackend.cpp:1230—view.titleno longer updates after page-initiated navigations (link click,window.location=, meta refresh): on base,Page.loadEventFiredchained aPageTitlefetch unconditionally so "the PageTitle handler settles a no-op and m_title still updates"; the newview->m_pendingNavigateguard skipschainTitle()when no user navigate is pending, leavingm_titlestale forever. Fix: drop them_pendingNavigategate and rely onnavGen— an idlechainTitle()stamps the current generation, and any laternavigate()bumps it viabeginChromeNavigation(), so the stale response is already dropped at theentry.navGen != view->m_navGenerationcheck.Extended reasoning...
Base (11a2e2c)
Page.loadEventFiredhandler:view->m_loading = false;then unconditionally enqueuesMethod::PageTitle; its response handler at line 842 writesview->m_titleandsettle()no-ops when the Navigate slot is empty — the base comment explicitly documents this: "If no navigate is pending (uninitiated navigation, redirect), the PageTitle handler settles a no-op and m_title still updates." After this PR, line 1230 isif (view->m_pendingNavigate && !view->m_navTitleChained) chainTitle();. Scenario:await view.navigate(pageA)resolves (settleSlot clearsm_pendingNavigate); the page then doeslocation.href = pageB. Chrome emitsPage.frameNavigated(setsm_loaderId, updatesm_url) andPage.loadEventFired;m_loaderIdis non-empty som_loading=falseruns, butm_pendingNavigateis null sochainTitle()is skipped andview->m_titlestill holds pageA's title.m_titleis written nowhere else in ChromeBackend.cpp. The comment justifies the guard as preventing an idle PageTitle from racing a laternavigate(), but that race is already closed by the…Verification: normal — this is a regression against base. Base (11a2e2c)
Page.loadEventFiredhandler, lines 1119-1123: ```cpp if (method.size() == 19 && memcmp(method.data(), "Page.loadEventFired", 19) == 0) { view->m_loading = false; uint32_t tid = nextId(); m_pending.add(tid, Pending { Method::PageTitle, PendingSlot::Navigate, view->m_viewId }); send(tid, Command(tid,… | normal —…
The loadEventFired handler gated the title fetch on a pending navigate(), so a link click or location.href left m_title stale. Drop the gate: the fetch's navGen entry already protects a later navigate() from the stale reply, and the settle is a no-op when no navigate is pending. Reset the per-document dedupe flag on each main-frame commit so consecutive page-initiated navigations each fetch once.
|
Confirmed, fixed in 0718511. The loadEventFired handler gated chainTitle() on m_pendingNavigate, so a page-initiated navigation left view.title stale. The gate is gone: the navGen stamp on the PageTitle entry already drops a reply that races a later navigate(), and the settle is a no-op when no navigate is pending. The gate removal alone was not enough: m_navTitleChained stayed set after a completed navigate(), so frameNavigated now resets it on each main-frame commit. A new mock-CDP test drives two consecutive page-initiated navigations. It fails before the fix (title stays stale) and passes after. |
A first-navigate timeout that fired between the Target.attachToTarget reply and the Page.enable reply made the stale-generation gate drop the Page.enable reply. That reply handler was the only sender of Runtime.enable and Page.setLifecycleEventsEnabled, so the session lost console events and waitUntil:'domcontentloaded' forever. Send both fire-and-forget commands from the attach handler, next to Page.enable. The dropped reply now only skips the timed-out Page.navigate.
|
Confirmed, fixed in 3ad2253. The PageEnable reply handler was the only sender of Runtime.enable and Page.setLifecycleEventsEnabled, so a first-navigate timeout that fired mid-attach dropped that reply at the stale gate and the session permanently lost console and lifecycle events. Both fire-and-forget commands now go out from the Target.attachToTarget handler, next to Page.enable. The dropped reply then only skips the timed-out Page.navigate, which is the correct cost. New mock-CDP test: the mock holds the Page.enable reply for 2s and only emits lifecycleEvent if it received setLifecycleEventsEnabled. It fails before the fix (the second navigate with waitUntil:'domcontentloaded' times out) and passes after. Full file: 10/10. |
|
Closing as stale: this PR conflicts with main, and its last commit is from 2026-09-02. The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR. |
Problem
await view.navigate(url)settles only onPage.loadEventFired. A page that keeps a subresource open (SSE, a hung<img>) never firesload, so the await hangs.goto().Fix
navigate,reload,goBack,goForwardtake{ waitUntil: "load" | "domcontentloaded", timeout }(defaults"load", 30000 ms,0disables). WebKit:"domcontentloaded"degrades to"load"(no DCL delegate hook).Page.lifecycleEvent. A"domcontentloaded"wait settles when the event'sframeIdandloaderIdmatch the main frame's lastPage.frameNavigated; replayed and subframe events never match."load"still usesPage.loadEventFired.JSWebView::armNavTimeoutschedules aWTF::RunLoop::dispatchAfterclosure keyed by{viewId, generation}. Settling the Navigate slot bumpsm_navGeneration, so a late timer does nothing. Navigate-slotPendingentries carry their generation, so a stale reply cannot settle a retry.test/js/bun/webview/webview-navigate-options.test.ts(new, mock CDP, 8 tests, no Chrome) and 5 real-Chrome tests inwebview-chrome.test.ts(all 63 pass). Also the rest oftest/js/bun/webview/andbun-types.test.ts.Background
JSWebViewholds one pending promise per slot (m_pendingNavigate, ...). The Chrome backend maps each CDP command id to aPending { method, slot, viewId }entry and settles that slot on reply.Page.lifecycleEventreportsDOMContentLoaded,load,networkIdleper frame andloaderId(one per document load). Enabling it replays the current document's events, hence the loaderId match.WTF::RunLoop::dispatchAfteris WebKit's delayed dispatch, backed byWTFTimeron bun's event loop. The timer has no cancel handle; the generation counter is the cancel.Notes
History. Opened 2026-05-13, all CI lanes green on build #54352, closed by the stale bot on 2026-09-02, reopened and rebased onto
main@6f27257the same day. The rebase had one conflict:JSWebViewConstructor.cppnow marks the constructor's navigate promise handled (#40992). Both are kept:markAsHandled()andtimeoutMs=0for the constructor's initial navigate. The generation bump moved into a sharedtakeSlothelper sorejectSlotAsHandled(close(), browser death) also invalidates an armed timer.Real Chrome. Chrome refuses to start as root without
--no-sandbox, so on a root container run the real-Chrome files withBUN_CHROME_PATHpointing at a wrapper script that adds the flag. The mock tests need nothing.Mock transport.
webview-navigate-options.test.tsdrives the connect-mode transport with aBun.serveWebSocket that speaks CDP.fake-chrome-fixture.ts(pipe mode) exists on main for the spawn path. Both fakes stay: the ws mock is the only CI coverage of connect mode, and the lifecycle scenarios (DCL-only, silent, stale load) are per-test behaviours that would need several new fixture flags.Gate. With
src/at base,webview-navigate-options.test.tsfails 7 of 8 (the default-loadtest passes). With the fix, 8 of 8.Deferred, needs a maintainer's scope call.
m_navPending. After a timeout the nextnavigate()rejects with "navigation already pending". Needs a newOp::CancelNavigateIPC message.view.close()works.Page.frameNavigatedcan re-arm the event gate in the sub-millisecond window where the timeout fires as the old navigation commits and the user retries in.catch(). Needs the expected loaderId from thePage.navigatereply (Playwright's LifecycleWatcher), whichPage.reloadandnavigateToHistoryEntrydo not return.Target.attachToTargetreply does not close its tab (one round trip aftercreateTargetsetm_targetId). NeedstargetIdcarried inPending. webview: close the tab created by a Target.createTarget that was in flight at close() #39075 covers theclose()side of this.goBack/goForwarddo not setm_loading = true;reload()does.view.titleno longer refreshes on page-initiated navigations.view.urlstill does throughframeNavigated.no test proof · iteration 0 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/js/bun/webview/webview-chrome.test.ts