Skip to content

Commit f70e847

Browse files
committed
Fix issue with using a custom user-data-dir in UC Mode
1 parent 9e10600 commit f70e847

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

seleniumbase/undetected/options.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,19 @@ def handle_prefs(self, user_data_dir):
4949
undot_prefs, self._undot_key(key, value)
5050
)
5151
prefs_file = os.path.join(default_path, "Preferences")
52-
if os.path.exists(prefs_file):
53-
with open(prefs_file, encoding="latin1", mode="r") as f:
54-
undot_prefs = self._merge_nested(json.load(f), undot_prefs)
55-
with open(prefs_file, encoding="latin1", mode="w") as f:
56-
json.dump(undot_prefs, f)
52+
try:
53+
if os.path.exists(prefs_file):
54+
with open(prefs_file, encoding="utf-8", mode="r") as f:
55+
undot_prefs = self._merge_nested(
56+
json.load(f), undot_prefs
57+
)
58+
except Exception:
59+
pass
60+
try:
61+
with open(prefs_file, encoding="utf-8", mode="w") as f:
62+
json.dump(undot_prefs, f)
63+
except Exception:
64+
pass
5765
# Remove experimental_options to avoid errors
5866
del self._experimental_options["prefs"]
5967
exclude_switches = self.experimental_options.get("excludeSwitches")

0 commit comments

Comments
 (0)