Skip to content

Commit

Permalink
3.5.2 - Minor changes and fixes
Browse files Browse the repository at this point in the history
* removed search paths for Chrome Canary and Chrome Beta from find_chrome_executable()
    since chromedriver is always behind schedule so that means a driver for newer versions than current main could not be found and raises Exception.

* Changed/Fixed wrong binary version caused by patcher.
  Due to multi-threading people and a mistake fromy my side,
  the driver binary currently on disk was always used instead of getting new ones. even if you did not use multithreading.
  so even outdated binaries where kept!
  for multithreading people, it now only keeps the most recent binary and throws away others.
  for normal people, you will get the binary you deserve ;)

* Added more descriptive exceptions when Chrome binary could not be found origin
  no connection could be made to Chrome.

* some stuff i forgot
  • Loading branch information
unknown committed Aug 9, 2023
1 parent 1f3d410 commit 44c5ea7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
17 changes: 14 additions & 3 deletions undetected_chromedriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
from __future__ import annotations


__version__ = "3.5.1a"
__version__ = "3.5.2"

import json
import logging
import os
import pathlib
import re
import shutil
import subprocess
Expand Down Expand Up @@ -372,6 +373,18 @@ def __init__(
browser_executable_path or find_chrome_executable()
)

if not options.binary_location or not \
pathlib.Path(options.binary_location).exists():
raise FileNotFoundError(
"\n---------------------\n"
"Could not determine browser executable."
"\n---------------------\n"
"Make sure your browser is installed in the default location (path).\n"
"If you are sure about the browser executable, you can specify it using\n"
"the `browser_executable_path='{}` parameter.\n\n"
.format("/path/to/browser/executable" if IS_POSIX else "c:/path/to/your/browser.exe")
)

self._delay = 3

self.user_data_dir = user_data_dir
Expand Down Expand Up @@ -877,8 +890,6 @@ def find_chrome_executable():
if item is not None:
for subitem in (
"Google/Chrome/Application",
"Google/Chrome Beta/Application",
"Google/Chrome Canary/Application",
):
candidates.add(os.sep.join((item, subitem, "chrome.exe")))
for candidate in candidates:
Expand Down
16 changes: 7 additions & 9 deletions undetected_chromedriver/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,16 @@ def auto(self, executable_path=None, force=False, version_main=None, _=None):
Returns:
"""
# if self.user_multi_procs and \
# self.user_multi_procs != -1:
# # -1 being a skip value used later in this block
#
p = pathlib.Path(self.data_path)
if self.user_multi_procs:
with Lock():
files = list(p.rglob("*chromedriver*?"))
for file in files:
if self.is_binary_patched(file):
self.executable_path = str(file)
return True
files = list(p.rglob("*chromedriver*"))
most_recent = max(files, key=lambda f: f.stat().st_mtime)
files.remove(most_recent)
list(map(lambda f: f.unlink(), files))
if self.is_binary_patched(most_recent):
self.executable_path = str(most_recent)
return True

if executable_path:
self.executable_path = executable_path
Expand Down

0 comments on commit 44c5ea7

Please sign in to comment.