File tree 1 file changed +21
-0
lines changed
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -141,7 +141,28 @@ def __init__(
141
141
options ._session = self
142
142
debug_host = "127.0.0.1"
143
143
debug_port = 9222
144
+ import requests
145
+
146
+ special_port_free = False # If the port isn't free, don't use 9222
147
+ try :
148
+ res = requests .get ("http://127.0.0.1:9222" )
149
+ if res .status_code != 200 :
150
+ raise Exception ("The port is free! It will be used!" )
151
+ except Exception :
152
+ # Use port 9222, which outputs to chrome://inspect/#devices
153
+ special_port_free = True
154
+ sys_argv = sys .argv
155
+ arg_join = " " .join (sys_argv )
156
+ from seleniumbase import config as sb_config
157
+
158
+ if (
159
+ (("-n" in sys .argv ) or (" -n=" in arg_join ) or ("-c" in sys .argv ))
160
+ or (hasattr (sb_config , "multi_proxy" ) and sb_config .multi_proxy )
161
+ or not special_port_free
162
+ ):
163
+ debug_port = selenium .webdriver .common .service .utils .free_port ()
144
164
if hasattr (options , "_remote_debugging_port" ):
165
+ # The user chooses the port. Errors happen if the port is taken.
145
166
debug_port = options ._remote_debugging_port
146
167
if not options .debugger_address :
147
168
options .debugger_address = "%s:%d" % (debug_host , debug_port )
You can’t perform that action at this time.
0 commit comments