Skip to content

fix(record): record a page reload instead of dropping it as a same-URL navigation - #184

Open
MaxFreedomPollard wants to merge 1 commit into
Tencent:mainfrom
MaxFreedomPollard:fix/record-reload-step
Open

fix(record): record a page reload instead of dropping it as a same-URL navigation#184
MaxFreedomPollard wants to merge 1 commit into
Tencent:mainfrom
MaxFreedomPollard:fix/record-reload-step

Conversation

@MaxFreedomPollard

Copy link
Copy Markdown

Problem

During recording, a page reload (F5, the reload button, or location.reload()) leaves no step in the trace. A flow that only takes effect after a refresh therefore stalls on replay, because the trace never says to reload (#139).

Root cause

observeRecordedNavigation opens with

if (!url || url === navigation.currentUrl) return { kind: "noop" };

The guard is there so the webNavigation.onCommitted / onCompleted pair of one navigation yields one step. A reload commits to the URL the tab is already on, so the same guard swallows it on the same line. The rest of the pipeline was already prepared for reloads: trace-reducer-v3.ts has carried reload: "reload" in TRANSITION_CAUSES, and the protocol defines NavigationCause::Reload, but the buffer never produced a draft that reached either.

Reproduced through the real recorder (start on https://example.com/, onCommitted with transitionType: "reload", onCompleted, stop): on main the exported v3 trace has steps: [].

Fix

One condition in step-buffer.ts: a commit whose transitionType is reload passes the same-URL guard. Only the committed event carries the transition type, so the completion that follows (same URL, no type) still collapses onto it and no duplicate is produced. The step reduces to { op: "navigate", to: <url>, cause: "reload" }, the shape the protocol already defines, so whoever replays the trace can issue bsk reload at that point.

Everything else is unchanged: action-caused navigations still annotate the action with navigatedTo, redirect hops still coalesce, and a reload triggered by pressing Enter in the address bar carries from_address_bar, which the reducer already maps to user_typed.

One consequence worth stating: Chrome reports reload for script-initiated reloads too, so a page that reloads itself is now recorded as well. Replaying bsk reload there is harmless and matches what the page actually did.

Tests

Three tests added (846 → 849), all failing on main with steps: []:

  • step-buffer.test.ts: a reload of the current page is appended as a navigate draft with transitionType: "reload"; the completion that follows still collapses onto it, so there is no duplicate.
  • record-steps.test.ts: end to end through handleRecordStartonCommitted(reload)onCompletedhandleRecordStop, the exported v3 trace has exactly one step, { op: "navigate", to: START_URL, cause: "reload" }, with pre- and post-states.

Verification

  • pnpm lint — exit 0 (biome, stylelint, dsh-plugin typecheck and tests)
  • pnpm --filter @browser-skill/extension compile — clean
  • pnpm ext:test — 76 files, 849 passed
  • pnpm ext:build — clean

Not exercised in a live Chrome here; the recorder harness in record-steps.test.ts drives the same webNavigation listeners the extension installs.

Closes #139

…L navigation

`observeRecordedNavigation` opens with a same-URL guard so the
`webNavigation.onCommitted` / `onCompleted` pair of one navigation yields a
single step. A reload commits to the URL the tab is already on, so the same
guard swallowed it: a recording in which the user pressed F5 or the reload
button exported no step at all, and replaying the trace stalls on any page
that only takes effect after a refresh (issue Tencent#139).

Let a commit whose transition type is `reload` through the guard. Only the
committed event carries the transition type, so the completion that follows
still collapses onto the recorded reload, and the `reload` entry that the v3
reducer's transition-cause table has carried all along (unreachable until
now) turns the step into `{op: "navigate", to: <url>, cause: "reload"}`,
the shape the protocol already defines.

Fixes Tencent#139
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

录制功能无法记录刷新页面的bsk reload操作

1 participant