Bundle patched ChromeDriver in Docker image
This commit is contained in:
+11
-2
@@ -22,6 +22,13 @@ from logger import get_logger
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
_DOWNLOAD_HEADERS = {
|
||||
"User-Agent": (
|
||||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
|
||||
"(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
def _get_chrome_full_version() -> tuple[int, str]:
|
||||
candidates = ["google-chrome", "google-chrome-stable", "chromium", "chromium-browser"]
|
||||
@@ -49,7 +56,8 @@ def _get_chrome_full_version() -> tuple[int, str]:
|
||||
def _latest_chromedriver_version(major: int) -> str:
|
||||
url = f"https://googlechromelabs.github.io/chrome-for-testing/LATEST_RELEASE_{major}"
|
||||
try:
|
||||
with urllib.request.urlopen(url, timeout=15) as resp:
|
||||
request = urllib.request.Request(url, headers=_DOWNLOAD_HEADERS)
|
||||
with urllib.request.urlopen(request, timeout=15) as resp:
|
||||
version = resp.read().decode().strip()
|
||||
log.info("Latest ChromeDriver for Chrome %d: %s", major, version)
|
||||
return version
|
||||
@@ -65,7 +73,8 @@ def _download_chromedriver(version: str, dest: Path) -> None:
|
||||
)
|
||||
log.info("Downloading ChromeDriver %s …", version)
|
||||
try:
|
||||
with urllib.request.urlopen(zip_url, timeout=60) as resp:
|
||||
request = urllib.request.Request(zip_url, headers=_DOWNLOAD_HEADERS)
|
||||
with urllib.request.urlopen(request, timeout=60) as resp:
|
||||
data = resp.read()
|
||||
except Exception as exc:
|
||||
log.critical("Download failed: %s", exc)
|
||||
|
||||
Reference in New Issue
Block a user