@@ -33,25 +33,22 @@ import { Browser } from '../browser';
3333import type * as types from '../types' ;
3434import type * as channels from '@protocol/channels' ;
3535import type { HTTPRequestParams } from '../../utils/network' ;
36- import { NET_DEFAULT_TIMEOUT } from '../../utils/network' ;
3736import { fetchData } from '../../utils/network' ;
3837import { getUserAgent } from '../../utils/userAgent' ;
3938import { wrapInASCIIBox } from '../../utils/ascii' ;
40- import { debugMode , headersArrayToObject , } from '../../utils' ;
39+ import { debugMode , headersArrayToObject , } from '../../utils' ;
4140import { removeFolders } from '../../utils/fileUtils' ;
4241import { RecentLogsCollector } from '../../common/debugLogger' ;
4342import type { Progress } from '../progress' ;
4443import { ProgressController } from '../progress' ;
4544import { TimeoutSettings } from '../../common/timeoutSettings' ;
4645import { helper } from '../helper' ;
4746import type { CallMetadata } from '../instrumentation' ;
48- import http from 'http' ;
49- import https from 'https' ;
47+ import type http from 'http' ;
5048import { registry } from '../registry' ;
5149import { ManualPromise } from '../../utils/manualPromise' ;
5250import { validateBrowserContextOptions } from '../browserContext' ;
5351import { chromiumSwitches } from './chromiumSwitches' ;
54- import { httpHappyEyeballsAgent , httpsHappyEyeballsAgent } from '../happy-eyeballs' ;
5552
5653const ARTIFACTS_FOLDER = path . join ( os . tmpdir ( ) , 'playwright-artifacts-' ) ;
5754
@@ -338,21 +335,11 @@ async function urlToWSEndpoint(progress: Progress, endpointURL: string) {
338335 return endpointURL ;
339336 progress . log ( `<ws preparing> retrieving websocket url from ${ endpointURL } ` ) ;
340337 const httpURL = endpointURL . endsWith ( '/' ) ? `${ endpointURL } json/version/` : `${ endpointURL } /json/version/` ;
341- const isHTTPS = endpointURL . startsWith ( 'https://' ) ;
342- const json = await new Promise < string > ( ( resolve , reject ) => {
343- ( isHTTPS ? https : http ) . get ( httpURL , {
344- timeout : NET_DEFAULT_TIMEOUT ,
345- agent : isHTTPS ? httpsHappyEyeballsAgent : httpHappyEyeballsAgent ,
346- } , resp => {
347- if ( resp . statusCode ! < 200 || resp . statusCode ! >= 400 ) {
348- reject ( new Error ( `Unexpected status ${ resp . statusCode } when connecting to ${ httpURL } .\n` +
349- `This does not look like a DevTools server, try connecting via ws://.` ) ) ;
350- }
351- let data = '' ;
352- resp . on ( 'data' , chunk => data += chunk ) ;
353- resp . on ( 'end' , ( ) => resolve ( data ) ) ;
354- } ) . on ( 'error' , reject ) ;
355- } ) ;
338+ const json = await fetchData ( {
339+ url : httpURL ,
340+ } , async ( _ , resp ) => new Error ( `Unexpected status ${ resp . statusCode } when connecting to ${ httpURL } .\n` +
341+ `This does not look like a DevTools server, try connecting via ws://.` )
342+ ) ;
356343 return JSON . parse ( json ) . webSocketDebuggerUrl ;
357344}
358345
0 commit comments