File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import {
1919 hasGraphicalEnvironment ,
2020} from './playwrightUtils.js' ;
2121import type { ServiceRegistry } from './serviceRegistry.js' ;
22+ import { isBrowserClosedError , LoginCancelledError } from './services/core/base.js' ;
2223import { RegisteredService } from './services/core/registered.js' ;
2324import type { Service } from './services/index.js' ;
2425
@@ -222,7 +223,19 @@ export async function authBrowserPrepare(
222223
223224 const launchOptions = getBrowserLaunchOptions ( config ) ;
224225
225- const apiCredentials = await session . prepare ( encryptedStorage , launchOptions ) ;
226+ let apiCredentials ;
227+ try {
228+ apiCredentials = await session . prepare ( encryptedStorage , launchOptions ) ;
229+ } catch ( error : unknown ) {
230+ // Closing the browser window during preparation should be reported to
231+ // the user as a clean cancellation rather than a stack trace. Doing
232+ // this here means every service's prepare() gets the same treatment
233+ // without having to repeat the wrapping in each implementation.
234+ if ( error instanceof Error && isBrowserClosedError ( error ) ) {
235+ throw new LoginCancelledError ( ) ;
236+ }
237+ throw error ;
238+ }
226239 apiCredentialStore . save ( service . name , apiCredentials ) ;
227240 return { alreadyPrepared : false } ;
228241}
You can’t perform that action at this time.
0 commit comments