fix(browser): drop session injection from extension exec results#1518
Merged
jackwener merged 1 commit intoMay 13, 2026
Merged
Conversation
`pageScopedResult()` in extension/src/background.ts was spreading the
lease's session into the result `data` for every page-scoped command. For
the `exec` action — which routes user JavaScript through page.evaluate()
— this contaminated arbitrary user-JS returns:
* Array / primitive returns came back as `{ session, data: <value> }`
envelopes. Adapters that did `Array.isArray(result)` got `false` and
treated the page as having no rows. Visible repro:
`opencli google search ...` and `opencli xiaohongshu search ...` —
Chrome rendered results correctly but adapters extracted an empty array
(reported in jackwener#1518 from the Browser Bridge v1.0.12 envelope).
* Plain-object returns had an extra `session` key spliced in, silently
overwriting any user `session` field with the lease's value.
Fix in the extension layer instead of compensating client-side:
`pageScopedResult` now returns `{ id, ok, data, page }` — the same form
it had before jackwener#1461 added the workspace→session refactor. Client-side
unwrapping is no longer needed and the original PR jackwener#1518 `Page.evaluate`
heuristic is dropped (it only covered the array path and would have
missed the plain-object path).
Two adapter improvements kept from the original PR:
* `clis/google/search.js` — wait for `#rso a h3` (with a 5s timeout)
before extracting. On Chrome 148 / Linux Wayland the DOM can settle
before SERP anchors are populated, so the existing fixed `wait 2`
could return empty even with the envelope fix.
* `clis/xiaohongshu/search.js` — extract initially visible cards before
scrolling, then merge post-scroll rows by URL. Xiaohongshu's
virtualized masonry can evict the initial note cards from the DOM
after scroll, causing extraction to return [] even though the
browser had rendered results correctly.
Extension version bumped to 1.0.14.
Repro environment (from jackwener#1518):
* OpenCLI 1.7.18
* Browser Bridge extension 1.0.12 → 1.0.14
* Chrome 148.0.7778.96
* Linux Wayland, Node 22.22.1
Tests: extension/src/background.test.ts navigate same-url assertion
updated to no longer expect `session` in `data`. Three Page.evaluate
unwrap test cases removed.
efb0619 to
9c64a54
Compare
jackwener
approved these changes
May 13, 2026
Owner
jackwener
left a comment
There was a problem hiding this comment.
LGTM. Verified the extension-side fix keeps exec/evaluate data raw by reverting pageScopedResult to { id, ok, data, page }, with no Page-side unwrap residue. Extension 1.0.14 version files and dist are synced; Google/Xiaohongshu adapter fixes are scoped and reasonable. Local checks: extension background 52/52, Page unit 21/21, Xiaohongshu adapter 19/19, root typecheck/build, extension typecheck/build, diff-check.
This was referenced May 13, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes browser-backed searches that can visually render results in Chrome but return empty /
NOT_FOUNDfrom adapters becausepageScopedResult()in the extension was injecting the lease'ssessioninto the resultdata. For theexecaction this contaminated arbitrary user-JavaScript returns:{ session, data: <value> }envelopes —Array.isArray(result)was false, adapters extracted nothing.sessionkey spliced in (and any usersessionfield was silently overwritten by the lease).Originally proposed (this PR's first commit) as a client-side unwrap in
Page.evaluate(). After upstream review the scope changed to fix the root cause in the extension and drop the client-side workaround.This PR now:
pageScopedResult()to its pre-refactor(browser): replace workspace with explicit sessions #1461 form ({ id, ok, data, page }). No session injection.Result.sessionis not added to the protocol — no consumers exist andResult.pagealready exposes routing identity. Bumps extension to 1.0.14.#rso a h3(5s) before extracting Google SERP, falling back to the existingwait 2. Avoids empty extraction on Chrome 148 / Linux Wayland when DOM settles before SERP anchors populate.Original commit attribution kept on @hansnow; scope rewritten with maintainer push.
Repro environment (from original report)
1.7.181.0.12→1.0.14148.0.7778.967.0.0-15-genericx86_64, Wayland22.22.1, npm:9.2.0Observed failure mode:
opencli google search "美食" --limit 5 --lang zh -f yamlopencli xiaohongshu search "美食" --limit 5 -f yamlChrome showed normal public search results, but adapters received non-array values and treated the extraction as empty.
Validation
npm run typechecknpm run buildnpx vitest run --project unit— 1083 passed (one unrelatedEADDRINUSEfrom daemon.test.ts port contention on local machine)npx vitest run --project extension— 64 passednpx vitest run --project adapter clis/xiaohongshu/ clis/google/— 113 passedvite build— 75.49 kBRoot cause history
The session injection in
pageScopedResultwas added by #1461 (refactor(browser): replace workspaces with sessions). The same refactor also caused the doctor connectivity regression fixed in 1.7.18 — both were silent breakages from a partial refactor that wasn't end-to-end smoke-tested. Lesson recorded for future large refactors.