@@ -47,40 +47,11 @@ export class BidiBrowser extends Browser {
47
47
if ( ( options as any ) . __testHookOnConnectToBrowser )
48
48
await ( options as any ) . __testHookOnConnectToBrowser ( ) ;
49
49
50
- let proxy : bidi . Session . ManualProxyConfiguration | undefined ;
51
- if ( options . proxy ) {
52
- proxy = {
53
- proxyType : 'manual' ,
54
- } ;
55
- const url = new URL ( options . proxy . server ) ; // Validate proxy server.
56
- switch ( url . protocol ) {
57
- case 'http:' :
58
- proxy . httpProxy = url . host ;
59
- break ;
60
- case 'https:' :
61
- proxy . httpsProxy = url . host ;
62
- break ;
63
- case 'socks4:' :
64
- proxy . socksProxy = url . host ;
65
- proxy . socksVersion = 4 ;
66
- break ;
67
- case 'socks5:' :
68
- proxy . socksProxy = url . host ;
69
- proxy . socksVersion = 5 ;
70
- break ;
71
- default :
72
- throw new Error ( 'Invalid proxy server protocol: ' + options . proxy . server ) ;
73
- }
74
- if ( options . proxy . bypass )
75
- proxy . noProxy = options . proxy . bypass . split ( ',' ) ;
76
- // TODO: support authentication.
77
- }
78
-
79
50
browser . _bidiSessionInfo = await browser . _browserSession . send ( 'session.new' , {
80
51
capabilities : {
81
52
alwaysMatch : {
82
53
acceptInsecureCerts : false ,
83
- proxy,
54
+ proxy : getProxyConfiguration ( options . proxy ) ,
84
55
unhandledPromptBehavior : {
85
56
default : bidi . Session . UserPromptHandlerType . Ignore ,
86
57
} ,
@@ -126,6 +97,7 @@ export class BidiBrowser extends Browser {
126
97
async doCreateNewContext ( options : types . BrowserContextOptions ) : Promise < BrowserContext > {
127
98
const { userContext } = await this . _browserSession . send ( 'browser.createUserContext' , {
128
99
acceptInsecureCerts : options . ignoreHTTPSErrors ,
100
+ proxy : getProxyConfiguration ( options . proxy ) ,
129
101
} ) ;
130
102
const context = new BidiBrowserContext ( this , userContext , options ) ;
131
103
await context . _initialize ( ) ;
@@ -473,6 +445,39 @@ function toBidiSameSite(sameSite: channels.SetNetworkCookie['sameSite']): bidi.N
473
445
return bidi . Network . SameSite . None ;
474
446
}
475
447
448
+ function getProxyConfiguration ( proxySettings ?: types . ProxySettings ) : bidi . Session . ManualProxyConfiguration | undefined {
449
+ if ( ! proxySettings )
450
+ return undefined ;
451
+
452
+ const proxy : bidi . Session . ManualProxyConfiguration = {
453
+ proxyType : 'manual' ,
454
+ } ;
455
+ const url = new URL ( proxySettings . server ) ; // Validate proxy server.
456
+ switch ( url . protocol ) {
457
+ case 'http:' :
458
+ proxy . httpProxy = url . host ;
459
+ break ;
460
+ case 'https:' :
461
+ proxy . sslProxy = url . host ;
462
+ break ;
463
+ case 'socks4:' :
464
+ proxy . socksProxy = url . host ;
465
+ proxy . socksVersion = 4 ;
466
+ break ;
467
+ case 'socks5:' :
468
+ proxy . socksProxy = url . host ;
469
+ proxy . socksVersion = 5 ;
470
+ break ;
471
+ default :
472
+ throw new Error ( 'Invalid proxy server protocol: ' + proxySettings . server ) ;
473
+ }
474
+ if ( proxySettings . bypass )
475
+ proxy . noProxy = proxySettings . bypass . split ( ',' ) ;
476
+ // TODO: support authentication.
477
+
478
+ return proxy ;
479
+ }
480
+
476
481
export namespace Network {
477
482
export const enum SameSite {
478
483
Strict = 'strict' ,
0 commit comments