Skip to content

fix(browser): goto 重试覆盖裸 'Page not found:' 失效身份#1869

Merged
jackwener merged 2 commits into
jackwener:mainfrom
huanghe:pr/stale-page-identity
Jun 15, 2026
Merged

fix(browser): goto 重试覆盖裸 'Page not found:' 失效身份#1869
jackwener merged 2 commits into
jackwener:mainfrom
huanghe:pr/stale-page-identity

Conversation

@huanghe

@huanghe huanghe commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

问题

Page.goto() 已有「stale page identity 自动重试」逻辑:当缓存的 targetId 失效(标签被外部关闭、identity 被驱逐)时,丢弃死 id 并经 session lease 重试一次。

但判定函数 isStalePageIdentityError() 只匹配错误信息里包含 stale page identity 的情况。在并发 adapter 调用下,扩展有时只抛出 Page not found: <id>(不带 — stale page identity 后缀)。这类错误没被识别为「身份失效」,于是不会重试——同一个死 targetId 被反复发送,导致后续调用连环失败。

改动

isStalePageIdentityError() 放宽为同时匹配 Page not found::

-  return message.includes('stale page identity');
+  return message.includes('stale page identity') || message.includes('Page not found:');

这样 goto() 在收到裸 Page not found: 时也会丢弃失效身份、重试一次。重试本身是安全的:只是清掉缓存 targetId 后让扩展的 session lease 重新解析到活标签(已有逻辑),_page 为空时仍照旧直接抛错、不重试。

测试

新增用例 retries on a bare "Page not found:" error without the stale-identity suffix:

  • 有本修复:src/browser/page.test.ts 25 个用例全部通过。
  • 去掉本修复(对照):该用例失败,第二次 goto() 直接抛 Page not found: deadbeef,证明它精确覆盖了新分支。

npx tsc --noEmit 通过。

…oto retry

The goto() stale-identity retry only matched errors containing 'stale page
identity'. Under concurrent adapter calls the extension can reject with just
'Page not found: <id>' (no suffix) when the cached targetId was evicted — those
were not retried, so a dead targetId cascaded into repeated failures across calls.

Broaden isStalePageIdentityError() to also match 'Page not found:' so goto()
drops the stale identity and retries once through the session lease.
@huanghe huanghe force-pushed the pr/stale-page-identity branch from d09bfa1 to c2978a7 Compare June 6, 2026 09:36
@huanghe

huanghe commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

补一句风险范围说明,方便快速确认这是个低回归面的改动:

核心改动只有 1 行 —— isStalePageIdentityError() 的匹配从 'stale page identity' 扩展为再认一种 message 形态 'Page not found:'。并发 adapter 调用下,extension 有时只回裸的 Page not found: <id>(不带 — stale page identity 后缀),但语义同样是「缓存的 targetId 已失效」。

happy path 一行未动 —— 改动全部在 goto() 已有的 catch 分支内;导航成功时根本不进 catch。

重试的双重 guard 保持不变:

if (!isStalePageIdentityError(err) || this._page === undefined) throw err;
  • 必须是 stale-identity 错误 之前确实缓存过 _page,才会 drop 掉死 id 重试;
  • fresh Page(_page === undefined,没有可丢弃的身份)仍直接抛,不会因为这次放宽识别范围而误重试;
  • 重试只发生一次(retry 的结果不再被 catch 包裹),即使极端情况下误判 Page not found:,最坏也只是多一次 navigate,不会 cascade 或循环。

测试:新增「裸 Page not found: 触发一次重试并切到新 page」用例;原有「无缓存身份 → 不重试、直接抛」用例保留,正好守住放宽匹配后 fresh-page 的防护没被破坏。src/browser/page.test.ts 覆盖这两条路径。

@jackwener jackwener merged commit 09a0af7 into jackwener:main Jun 15, 2026
11 checks passed
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.

2 participants