I'm trying to run a Brave browser with undetected_chrome on a Debian server.
Attempt 1: Using undected_chrome library and binary_location Result: undected_chrome has problem with driver.quit() not working probably, while I need to close and reopen the browser every minutes. People suggest using Seleniumbase instead.
Attempt 2: Using Seleniumbase and binary_location Result: Seleniumbase say that brave.exe is not a valid binary.
Attempt 3: Changing constants.py in Seleniumbase to include brave.exe
valid_chrome_binaries_on_windows = [
"chrome.exe",
"chromium.exe",
"brave.exe",
]
then using binary_location to run on Windows with the code below:
from seleniumbase import Driver
brave_path = r'C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe'
driver = Driver(uc=True, proxy=webdriver_proxy, incognito=True, page_load_strategy=load_strategy, block_images=True, binary_location=brave_path)
Result: Everything works well
Attempt 4: Repeat attempt 3 but on a Debian server
Change constants.py in Seleniumbase to include brave-browser
valid_chrome_binaries_on_linux = [
"google-chrome",
"google-chrome-stable",
"chrome",
"chromium",
"chromium-browser",
"google-chrome-beta",
"google-chrome-dev",
"google-chrome-unstable",
"brave-browser",
"brave-browser-stable",
]
then run this code on a Debian server:
brave_path = "/usr/bin/brave-browser"
driver = Driver(uc=True, proxy=webdriver_proxy, incognito=True, page_load_strategy=load_strategy, block_images=True, binary_location=brave_path)
Result: It works somewhat, it can access webpage but for some reason it misses some headers which trigger bot detection from sites. Using whatismyheader.com, here are a normal Brave header and the test code header side by side:
Normal Brave Header(using Brave with undetected_chrome library):
<html><head></head><body>GET / HTTP/1.1
Host: whatismyheader.com
Connection: keep-alive
Sec-Ch-Ua: "Brave";v="119", "Chromium";v="119", "Not?A_Brand";v="24"
Sec-Ch-Ua-Mobile: ?0
Sec-Ch-Ua-Platform: "Linux"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8
Sec-Gpc: 1
Accept-Language: en-US,en;q=0.8
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br
Test code header (using Brave with modified Seleniumbase):
<html><head></head><body>GET / HTTP/1.1
Host: whatismyheader.com
Connection: keep-alive
Sec-Ch-Ua:
Sec-Ch-Ua-Mobile: ?0
Sec-Ch-Ua-Platform: ""
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.1.60.118 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8
Sec-Gpc: 1
Accept-Language: en-US,en;q=0.6
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br
Anyone has any insight?
Thanks for the help.
Upgrade to seleniumbase 4.21.6
(or newer) so that you can use Brave or Opera. (https://github.com/seleniumbase/SeleniumBase/issues/2324) (Set via binary_location
). Eg. On a Mac:
pytest basic_test.py --binary-location="/Applications/Opera.app/Contents/MacOS/Opera"
pytest basic_test.py --binary-location="/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
For the formats that use the Driver()
or SB()
managers, the binary_location
arg should be set.
(Note that browser="chrome"
should still be used for this, as this will invoke chromedriver
with default options.)
If your issue is with the user-agent, you can set it with the agent
arg.
For me, I didn't need to change the user agent at all for UC Mode to work.
I used default UC Mode options while setting the updated binary location.