fix(browser): restore res.json before error handling in withRouteTabContext

The intercepted res.json was not restored on exceptions from run(),
causing handleRouteError -> jsonError to hit the buffer interceptor
instead of actually sending the error response. This could leave
HTTP requests hanging on any Playwright failure in tab-targeting routes.

Addresses codex-connector P1 on PR #30323.
This commit is contained in:
zeroaltitude 2026-03-03 20:17:30 -07:00
parent 52f4f9c6b4
commit 9dddc5e517
No known key found for this signature in database
GPG Key ID: 77592FB1C703882E

View File

@ -133,11 +133,18 @@ export async function withRouteTabContext<T>(
return params.res;
};
const result = await params.run({
profileCtx,
tab,
cdpUrl: profileCtx.profile.cdpUrl,
});
let result: T | undefined;
try {
result = await params.run({
profileCtx,
tab,
cdpUrl: profileCtx.profile.cdpUrl,
});
} catch (runErr) {
// Restore original res.json so error handling can actually send.
params.res.json = originalJson;
throw runErr;
}
// Now enrich and flush the intercepted response body.
if (jsonCalled) {