Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Andrew/user data dir #16

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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"

@@ -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
@@ -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: