Skip to content

Commit 9771990

Browse files
committed
add user-data-dir option
1 parent f102fb2 commit 9771990

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

dash/testing/browser.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import warnings
88
import percy
99
import requests
10+
import tempfile
1011

1112
from selenium import webdriver
1213
from selenium.webdriver.support import expected_conditions as EC
@@ -500,6 +501,22 @@ def _get_chrome(self):
500501
options.add_argument("--disable-gpu")
501502
options.add_argument("--remote-debugging-port=9222")
502503

504+
if not self._remote:
505+
try:
506+
# Create a TemporaryDirectory object.
507+
# It will be cleaned up when self._temp_user_data_dir_manager.cleanup() is called,
508+
# or when the object is garbage collected if not cleaned up explicitly.
509+
self._temp_user_data_dir_manager = tempfile.TemporaryDirectory()
510+
user_data_dir_path = self._temp_user_data_dir_manager.name
511+
options.add_argument(f"--user-data-dir={user_data_dir_path}")
512+
logger.info(
513+
f"Chrome using temporary user data directory: {user_data_dir_path}"
514+
)
515+
except Exception as e:
516+
logger.error(
517+
f"Could not create temporary directory for user-data-dir: {e}"
518+
)
519+
503520
chrome = (
504521
webdriver.Remote(command_executor=self._remote_url, options=options) # type: ignore[reportAttributeAccessIssue]
505522
if self._remote

0 commit comments

Comments
 (0)