File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -103,6 +103,22 @@ export function isBrowserClosedError(error: Error): boolean {
103103 ) ;
104104}
105105
106+ /**
107+ * Detects the Playwright/CDP error raised when a response body can no longer be
108+ * retrieved (`Network.getResponseBody` reports "No resource with given
109+ * identifier found"). This happens for responses that retain no readable body —
110+ * redirects, evicted or cached resources, or bodies fetched after the page has
111+ * navigated onward. Callers that read response bodies opportunistically should
112+ * treat this as inconclusive rather than fatal.
113+ */
114+ export function isResponseBodyUnavailableError ( error : Error ) : boolean {
115+ const message = error . message . toLowerCase ( ) ;
116+ return (
117+ message . includes ( 'no resource with given identifier' ) ||
118+ message . includes ( 'network.getresponsebody' )
119+ ) ;
120+ }
121+
106122export function isTimeoutError ( error : Error ) : boolean {
107123 return error . name === 'TimeoutError' ;
108124}
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ import {
3232 LoginFailedError ,
3333 LoginCancelledError ,
3434 isBrowserClosedError ,
35+ isResponseBodyUnavailableError ,
3536 isTimeoutError ,
3637} from '../core/base.js' ;
3738import type { EncryptedStorage } from '../../encryptedStorage.js' ;
@@ -530,9 +531,14 @@ function checkGoogleLoginResponse(
530531 . catch ( ( error : unknown ) => {
531532 // The response body can become unreadable if the page/context
532533 // closes while it's still being read (e.g. the automation
533- // navigates onward, or the user closes the browser). Treat that
534- // specific race as inconclusive; let any other error propagate.
535- if ( error instanceof Error && isBrowserClosedError ( error ) ) {
534+ // navigates onward, or the user closes the browser), or if the
535+ // response simply retains no readable body (redirects, cached or
536+ // evicted resources). Login detection here is best-effort, so treat
537+ // those cases as inconclusive; let any other error propagate.
538+ if (
539+ error instanceof Error &&
540+ ( isBrowserClosedError ( error ) || isResponseBodyUnavailableError ( error ) )
541+ ) {
536542 return ;
537543 }
538544 throw error ;
Original file line number Diff line number Diff line change 1+ import { describe , it , expect } from 'vitest' ;
2+ import {
3+ isBrowserClosedError ,
4+ isResponseBodyUnavailableError ,
5+ } from '../src/services/core/base.js' ;
6+
7+ describe ( 'isResponseBodyUnavailableError' , ( ) => {
8+ it ( 'recognizes the CDP "no resource with given identifier" error' , ( ) => {
9+ const error = new Error (
10+ 'Protocol error (Network.getResponseBody): No resource with given identifier found'
11+ ) ;
12+ expect ( isResponseBodyUnavailableError ( error ) ) . toBe ( true ) ;
13+ } ) ;
14+
15+ it ( 'matches case-insensitively' , ( ) => {
16+ expect (
17+ isResponseBodyUnavailableError ( new Error ( 'NO RESOURCE WITH GIVEN IDENTIFIER FOUND' ) )
18+ ) . toBe ( true ) ;
19+ } ) ;
20+
21+ it ( 'does not match unrelated errors' , ( ) => {
22+ expect ( isResponseBodyUnavailableError ( new Error ( 'something else went wrong' ) ) ) . toBe ( false ) ;
23+ } ) ;
24+
25+ it ( 'is distinct from browser-closed errors' , ( ) => {
26+ const bodyError = new Error (
27+ 'Protocol error (Network.getResponseBody): No resource with given identifier found'
28+ ) ;
29+ expect ( isBrowserClosedError ( bodyError ) ) . toBe ( false ) ;
30+ } ) ;
31+ } ) ;
You can’t perform that action at this time.
0 commit comments