@@ -32,12 +32,13 @@ class PlaywrightContext(iLibraryContext):
3232 current_page : any = None
3333 current_iframe = None
3434
35- page_support_options = ['accept_downloads' , 'bypass_csp' , 'color_scheme' , 'device_scale_factor' , 'extra_http_headers' , 'geolocation' , 'has_touch' , 'http_credentials' , 'ignore_https_errors' , 'is_mobile' , 'java_script_enabled' , 'locale' , 'no_viewport' , 'offline' , 'permissions' , 'proxy' , 'record_har_omit_content' , 'record_har_path' , 'record_video_dir' , 'record_video_size' , 'timezone_id' , 'user_agent' , 'viewport' ]
36-
35+ page_support_options = ['accept_downloads' , 'bypass_csp' , 'color_scheme' , 'device_scale_factor' , 'extra_http_headers' , 'geolocation' , 'has_touch' , 'http_credentials' , 'ignore_https_errors' , 'is_mobile' ,
36+ 'java_script_enabled' , 'locale' , 'no_viewport' , 'offline' , 'permissions' , 'proxy' , 'record_har_omit_content' , 'record_har_path' , 'record_video_dir' , 'record_video_size' , 'timezone_id' , 'user_agent' , 'viewport' ]
37+
3738 def __init__ (self , browser_type : str ):
3839 super ().__init__ (browser_type )
3940
40- async def start_server (self , options : dict = {}):
41+ async def start_server (self , options : dict = {}):
4142 default_options = {
4243 'slowMo' : 0 ,
4344 'headless' : True ,
@@ -54,9 +55,11 @@ async def start_server(self, options: dict={}):
5455 if key in ['headless' , 'devtools' , 'accept_downloads' , 'is_mobile' ]:
5556 merged_options [key ] = str2bool (merged_options [key ])
5657 elif key == 'width' :
57- merged_options ['viewport' ]['width' ] = str2int (merged_options [key ])
58+ merged_options ['viewport' ]['width' ] = str2int (
59+ merged_options [key ])
5860 elif key == 'height' :
59- merged_options ['viewport' ]['height' ] = str2int (merged_options [key ])
61+ merged_options ['viewport' ]['height' ] = str2int (
62+ merged_options [key ])
6063 elif key in ['slowMo' ]:
6164 merged_options [key ] = str2int (merged_options [key ])
6265
@@ -65,8 +68,14 @@ async def start_server(self, options: dict={}):
6568 self .playwright = await async_playwright ().start ()
6669
6770 if self .browser_type == "chrome" or self .browser_type == "pwchrome" :
71+ proxy = None
72+ if 'proxy' in merged_options :
73+ proxy = merged_options ['proxy' ]
74+ # Chromium can use proxy only via global launch
75+ del merged_options ['proxy' ]
6876 self .browser = await self .playwright .chromium .launch (
69- headless = merged_options ['headless' ])
77+ headless = merged_options ['headless' ], proxy = proxy )
78+ merged_options
7079 elif self .browser_type == "webkit" :
7180 self .browser = await self .playwright .webkit .launch (
7281 headless = merged_options ['headless' ])
@@ -78,7 +87,7 @@ async def start_server(self, options: dict={}):
7887 async def stop_server (self ):
7988 await self .playwright .stop ()
8089 self ._reset_server_context ()
81-
90+
8291 def is_server_started (self ) -> bool :
8392 if self .browser is not None :
8493 return True
@@ -88,7 +97,7 @@ def set_default_timeout(self, timeout):
8897 self .timeout = timeout
8998 self .get_current_page ().get_page ().set_default_timeout (timeout * 1000 )
9099
91- async def create_new_page (self , options : dict = {}) -> BasePage :
100+ async def create_new_page (self , options : dict = {}) -> BasePage :
92101 device_options = {
93102 'accept_downloads' : True ,
94103 'viewport' : {
@@ -101,25 +110,29 @@ async def create_new_page(self, options: dict={}) -> BasePage:
101110 if support_key in options :
102111 device_options [support_key ] = options [support_key ]
103112 if support_key in ['accept_downloads' , 'ignore_https_errors' ]:
104- device_options [support_key ] = str2bool (device_options [support_key ])
113+ device_options [support_key ] = str2bool (
114+ device_options [support_key ])
105115
106116 # Force support viewport
107117 if support_key == 'viewport' :
108118 if 'width' in options .keys ():
109- device_options ['viewport' ]['width' ] = str2int (options ['width' ])
119+ device_options ['viewport' ]['width' ] = str2int (
120+ options ['width' ])
110121 if 'height' in device_options .keys ():
111- device_options ['viewport' ]['height' ] = str2int (options ['height' ])
122+ device_options ['viewport' ]['height' ] = str2int (
123+ options ['height' ])
112124
113125 if 'emulate' in options :
114126 device_options = self .playwright .devices [options ['emulate' ]]
115127
116128 if 'state_ref' in options :
117- device_options ['storage_state' ] = './states/state-' + options ['state_ref' ] + '.json'
129+ device_options ['storage_state' ] = './states/state-' + \
130+ options ['state_ref' ] + '.json'
118131
119132 new_page = await self .browser .new_page (** device_options )
120133 self .current_page = PlaywrightPage (new_page )
121134 return self .current_page
122-
135+
123136 def get_current_page (self ) -> BasePage :
124137 return self .current_page
125138
@@ -170,14 +183,13 @@ async def start_tracing(self):
170183 async def stop_tracing (self , path ):
171184 if len (self .browser .contexts ) > 0 :
172185 await self .browser .contexts [0 ].tracing .stop (path = path )
173-
186+
174187 def _reset_context (self ):
175188 self .browser = None
176189 self .current_context = None
177190 self .current_page = None
178191 self .current_iframe = None
179-
192+
180193 def _reset_server_context (self ):
181194 self ._reset_context ()
182195 self .playwright = None
183-
0 commit comments