Skip to content

Commit

Permalink
Merge pull request #16 from geopozo/andrew/user-data-dir
Browse files Browse the repository at this point in the history
Andrew/user data dir
  • Loading branch information
neyberson authored Aug 20, 2024
2 parents f5464dc + 63e38c4 commit 591537b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ __pycache__

# editor files
*.sw*

# ipynb
.ipynb_checkpoints/
4 changes: 4 additions & 0 deletions devtools/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import sys
import subprocess
import signal
import tempfile


class Browser:
def __init__(self, debug=None, path=None, headless=True):
self.pipe = Pipe()
self.temp_dir = tempfile.TemporaryDirectory()

if not debug: # false o None
stderr = subprocess.DEVNULL
Expand All @@ -28,6 +30,7 @@ def __init__(self, debug=None, path=None, headless=True):

new_env = os.environ.copy()
new_env["CHROMIUM_PATH"] = path
new_env["USER_DATA_DIR"] = self.temp_dir.name
if headless:
new_env["HEADLESS"] = "--headless"

Expand Down Expand Up @@ -74,6 +77,7 @@ def close_browser(self):
self.subprocess.terminate()
self.subprocess.wait(5)
self.subprocess.kill()
self.temp_dir.cleanup()

def send_command(self, command, params=None, cb=None):
return self.protocol.send_command(self, command, params, cb)
4 changes: 4 additions & 0 deletions devtools/chrome_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
else:
path = os.environ["CHROMIUM_PATH"]

user_data_dir = os.environ["USER_DATA_DIR"]

cli = [
path,
"--remote-debugging-pipe",
"--disable-breakpad",
"--allow-file-access-from-files",
f"--user-data-dir={user_data_dir}",
"--no-first-run"
]

if "HEADLESS" in os.environ:
Expand Down

0 comments on commit 591537b

Please sign in to comment.