Skip to content

[codex] Fix YouTube Browser Bridge envelope handling#1730

Open
ppop123 wants to merge 1 commit into
jackwener:mainfrom
ppop123:codex/youtube-bridge-envelope
Open

[codex] Fix YouTube Browser Bridge envelope handling#1730
ppop123 wants to merge 1 commit into
jackwener:mainfrom
ppop123:codex/youtube-bridge-envelope

Conversation

@ppop123
Copy link
Copy Markdown

@ppop123 ppop123 commented May 23, 2026

Problem

opencli youtube search can return an empty JSON array even when the loaded YouTube results page contains video rows.

Example command that reproduced the issue locally:

opencli youtube search "first time in China vlog" --limit 3 --type video -f json --window background

Before this patch the command exited successfully but printed:

[]

Root cause

The YouTube DOM extractor itself was not empty: the page had window.ytInitialData and videoRenderer entries. The failure happened at the Browser Bridge boundary.

Some Browser Bridge / daemon combinations return page.evaluate(...) payloads wrapped as:

{
  "session": "browser:default",
  "data": [ /* actual evaluate return value */ ]
}

Several YouTube adapters validated the raw page.evaluate() result directly, for example with Array.isArray(data) or object checks. With the wrapper present, a valid array looked like a plain object, so commands such as youtube search silently fell through to [] or treated the response as malformed.

youtube transcript already had its own local unwrapping helper, which is why this was an uneven YouTube-only compatibility gap rather than a totally new pattern.

Fix

  • Add a shared unwrapBrowserResult() helper in clis/youtube/utils.js.
  • Apply it at the page.evaluate() boundary across YouTube adapters that consume Browser Bridge results:
    • search, comments, feed, history, subscriptions
    • playlist, watch-later, video, channel
    • like, unlike, subscribe, unsubscribe
  • Refactor transcript to use the shared YouTube helper instead of keeping a duplicate local function.
  • Add regression coverage for envelope-wrapped youtube search results and helper behavior.

Why scoped to YouTube adapters

This PR does not change the Browser Bridge protocol or globally unwrap Page.evaluate() results. Many existing adapters already unwrap at their own adapter boundary, and global unwrapping would be a wider compatibility change with more blast radius. The immediate user-visible regression was in YouTube commands, so this keeps the fix narrow and consistent with nearby adapter patterns.

Verification

npx vitest run --project adapter clis/youtube/search.test.js clis/youtube/utils.test.js
npx vitest run --project adapter clis/youtube
npm run typecheck
npm run build
node dist/src/main.js youtube search "first time in China vlog" --limit 3 --type video -f json --window background

The final live smoke test returned 3 YouTube video rows instead of [].

I also scanned clis/youtube/*.js for non-test page.evaluate callers and confirmed they now go through unwrapBrowserResult where applicable.

@ppop123 ppop123 force-pushed the codex/youtube-bridge-envelope branch from 0eb9bd2 to 72767db Compare May 23, 2026 06:15
@ppop123 ppop123 marked this pull request as ready for review May 23, 2026 06:16
@ppop123 ppop123 force-pushed the codex/youtube-bridge-envelope branch from 72767db to 668caac Compare May 23, 2026 06:21
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.

1 participant