@@ -96,6 +96,105 @@ def linux_browser_apps_to_cmd(*apps):
9696 )
9797
9898
99+ def chrome_on_linux_path (prefer_chromium = False ):
100+ if os_name () != "linux" :
101+ return ""
102+ primary_chrome = "google-chrome"
103+ secondary_chrome = "chromium"
104+ if prefer_chromium :
105+ primary_chrome = "chromium"
106+ secondary_chrome = "google-chrome"
107+ paths = os .environ ["PATH" ].split (os .pathsep )
108+ binaries = []
109+ binaries .append (primary_chrome )
110+ binaries .append (secondary_chrome )
111+ binaries .append ("chromium-browser" )
112+ binaries .append ("chrome" )
113+ binaries .append ("google-chrome-stable" )
114+ binaries .append ("google-chrome-beta" )
115+ binaries .append ("google-chrome-dev" )
116+ binaries .append ("google-chrome-unstable" )
117+ for binary in binaries :
118+ for path in paths :
119+ full_path = os .path .join (path , binary )
120+ if os .path .exists (full_path ) and os .access (full_path , os .X_OK ):
121+ return full_path
122+ return "/usr/bin/google-chrome"
123+
124+
125+ def edge_on_linux_path ():
126+ if os_name () != "linux" :
127+ return ""
128+ paths = os .environ ["PATH" ].split (os .pathsep )
129+ binaries = []
130+ binaries .append ("microsoft-edge" )
131+ binaries .append ("microsoft-edge-stable" )
132+ binaries .append ("microsoft-edge-beta" )
133+ binaries .append ("microsoft-edge-dev" )
134+ for binary in binaries :
135+ for path in paths :
136+ full_path = os .path .join (path , binary )
137+ if os .path .exists (full_path ) and os .access (full_path , os .X_OK ):
138+ return full_path
139+ return "/usr/bin/microsoft-edge"
140+
141+
142+ def chrome_on_windows_path ():
143+ if os_name () != "win32" :
144+ return ""
145+ candidates = []
146+ for item in map (
147+ os .environ .get ,
148+ (
149+ "PROGRAMFILES" ,
150+ "PROGRAMFILES(X86)" ,
151+ "LOCALAPPDATA" ,
152+ "PROGRAMW6432" ,
153+ ),
154+ ):
155+ for subitem in (
156+ "Google/Chrome/Application" ,
157+ "Google/Chrome Beta/Application" ,
158+ "Google/Chrome Canary/Application" ,
159+ ):
160+ try :
161+ candidates .append (os .sep .join ((item , subitem , "chrome.exe" )))
162+ except TypeError :
163+ pass
164+ for candidate in candidates :
165+ if os .path .exists (candidate ) and os .access (candidate , os .X_OK ):
166+ return os .path .normpath (candidate )
167+ return ""
168+
169+
170+ def edge_on_windows_path ():
171+ if os_name () != "win32" :
172+ return ""
173+ candidates = []
174+ for item in map (
175+ os .environ .get ,
176+ (
177+ "PROGRAMFILES" ,
178+ "PROGRAMFILES(X86)" ,
179+ "LOCALAPPDATA" ,
180+ "PROGRAMW6432" ,
181+ ),
182+ ):
183+ for subitem in (
184+ "Microsoft/Edge/Application" ,
185+ "Microsoft/Edge Beta/Application" ,
186+ "Microsoft/Edge Canary/Application" ,
187+ ):
188+ try :
189+ candidates .append (os .sep .join ((item , subitem , "msedge.exe" )))
190+ except TypeError :
191+ pass
192+ for candidate in candidates :
193+ if os .path .exists (candidate ) and os .access (candidate , os .X_OK ):
194+ return os .path .normpath (candidate )
195+ return ""
196+
197+
99198def windows_browser_apps_to_cmd (* apps ):
100199 """Create analogue of browser --version command for windows."""
101200 powershell = determine_powershell ()
@@ -106,63 +205,21 @@ def windows_browser_apps_to_cmd(*apps):
106205 return '%s -NoProfile "%s"' % (powershell , script )
107206
108207
109- def get_binary_location (browser_type ):
208+ def get_binary_location (browser_type , prefer_chromium = False ):
209+ """Return the full path of the browser binary.
210+ If going for better results in UC Mode, use: prefer_chromium=True"""
110211 cmd_mapping = {
111212 ChromeType .GOOGLE : {
112- OSType .LINUX : linux_browser_apps_to_cmd (
113- "google-chrome-stable" ,
114- "google-chrome" ,
115- "chrome" ,
116- "chromium" ,
117- "chromium-browser" ,
118- "google-chrome-beta" ,
119- "google-chrome-dev" ,
120- "google-chrome-unstable" ,
121- ),
213+ OSType .LINUX : chrome_on_linux_path (prefer_chromium ),
122214 OSType .MAC : r"/Applications/Google Chrome.app"
123215 r"/Contents/MacOS/Google Chrome" ,
124- OSType .WIN : windows_browser_apps_to_cmd (
125- r'(Get-Item -Path "$env:PROGRAMFILES\Google\Chrome'
126- r'\Application\chrome.exe")' ,
127- r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Google\Chrome'
128- r'\Application\chrome.exe")' ,
129- r'(Get-Item -Path "$env:LOCALAPPDATA\Google\Chrome'
130- r'\Application\chrome.exe")' ,
131- ),
216+ OSType .WIN : chrome_on_windows_path (),
132217 },
133218 ChromeType .MSEDGE : {
134- OSType .LINUX : linux_browser_apps_to_cmd (
135- "microsoft-edge-stable" ,
136- "microsoft-edge" ,
137- "microsoft-edge-beta" ,
138- "microsoft-edge-dev" ,
139- ),
219+ OSType .LINUX : edge_on_linux_path (),
140220 OSType .MAC : r"/Applications/Microsoft Edge.app"
141221 r"/Contents/MacOS/Microsoft Edge" ,
142- OSType .WIN : windows_browser_apps_to_cmd (
143- # stable edge
144- r'(Get-Item -Path "$env:PROGRAMFILES\Microsoft\Edge'
145- r'\Application\msedge.exe")' ,
146- r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Microsoft'
147- r'\Edge\Application\msedge.exe")' ,
148- # beta edge
149- r'(Get-Item -Path "$env:LOCALAPPDATA\Microsoft\Edge Beta'
150- r'\Application\msedge.exe")' ,
151- r'(Get-Item -Path "$env:PROGRAMFILES\Microsoft\Edge Beta'
152- r'\Application\msedge.exe")' ,
153- r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Microsoft\Edge Beta'
154- r'\Application\msedge.exe")' ,
155- # dev edge
156- r'(Get-Item -Path "$env:LOCALAPPDATA\Microsoft\Edge Dev'
157- r'\Application\msedge.exe")' ,
158- r'(Get-Item -Path "$env:PROGRAMFILES\Microsoft\Edge Dev'
159- r'\Application\msedge.exe")' ,
160- r'(Get-Item -Path "$env:PROGRAMFILES (x86)\Microsoft\Edge Dev'
161- r'\Application\msedge.exe")' ,
162- # canary edge
163- r'(Get-Item -Path "$env:LOCALAPPDATA\Microsoft\Edge SxS'
164- r'\Application\msedge.exe")' ,
165- ),
222+ OSType .WIN : edge_on_windows_path (),
166223 },
167224 }
168225 return cmd_mapping [browser_type ][os_name ()]
@@ -185,11 +242,11 @@ def get_browser_version_from_os(browser_type):
185242 cmd_mapping = {
186243 ChromeType .GOOGLE : {
187244 OSType .LINUX : linux_browser_apps_to_cmd (
188- "google-chrome-stable" ,
189245 "google-chrome" ,
190- "chrome" ,
191246 "chromium" ,
192247 "chromium-browser" ,
248+ "chrome" ,
249+ "google-chrome-stable" ,
193250 "google-chrome-beta" ,
194251 "google-chrome-dev" ,
195252 "google-chrome-unstable" ,
@@ -212,8 +269,8 @@ def get_browser_version_from_os(browser_type):
212269 },
213270 ChromeType .MSEDGE : {
214271 OSType .LINUX : linux_browser_apps_to_cmd (
215- "microsoft-edge-stable" ,
216272 "microsoft-edge" ,
273+ "microsoft-edge-stable" ,
217274 "microsoft-edge-beta" ,
218275 "microsoft-edge-dev" ,
219276 ),
0 commit comments