summaryrefslogtreecommitdiff
path: root/crocoite/browser.py
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2018-11-14 18:40:28 +0100
committerLars-Dominik Braun <lars@6xq.net>2018-11-14 18:40:28 +0100
commit20634f87124e0529f45db4e5e801f1bb5c6de32c (patch)
tree27f5307865f3a5188a71a7d14f1790bb021034a2 /crocoite/browser.py
parentf273341d6486f139eed073e4664b985209567e96 (diff)
downloadcrocoite-20634f87124e0529f45db4e5e801f1bb5c6de32c.tar.gz
crocoite-20634f87124e0529f45db4e5e801f1bb5c6de32c.tar.bz2
crocoite-20634f87124e0529f45db4e5e801f1bb5c6de32c.zip
Async chrome process startup
Move it to .devtools. Seems more fitting.
Diffstat (limited to 'crocoite/browser.py')
-rw-r--r--crocoite/browser.py72
1 files changed, 0 insertions, 72 deletions
diff --git a/crocoite/browser.py b/crocoite/browser.py
index 515d06b..1b6debf 100644
--- a/crocoite/browser.py
+++ b/crocoite/browser.py
@@ -357,75 +357,3 @@ class SiteLoader:
self.logger.warning ('js dialog unknown',
uuid='3ef7292e-8595-4e89-b834-0cc6bc40ee38', **kwargs)
-import subprocess, os, time
-from tempfile import mkdtemp
-import shutil
-
-class ChromeService:
- """ Start Google Chrome listening on a random port """
-
- __slots__ = ('binary', 'windowSize', 'p', 'userDataDir')
-
- def __init__ (self, binary='google-chrome-stable', windowSize=(1920, 1080)):
- self.binary = binary
- self.windowSize = windowSize
- self.p = None
-
- def __enter__ (self):
- assert self.p is None
- self.userDataDir = mkdtemp ()
- args = [self.binary,
- '--window-size={},{}'.format (*self.windowSize),
- '--user-data-dir={}'.format (self.userDataDir), # use temporory user dir
- '--no-default-browser-check',
- '--no-first-run', # don’t show first run screen
- '--disable-breakpad', # no error reports
- '--disable-extensions',
- '--disable-infobars',
- '--disable-notifications', # no libnotify
- '--headless',
- '--disable-gpu',
- '--hide-scrollbars', # hide scrollbars on screenshots
- '--mute-audio', # don’t play any audio
- '--remote-debugging-port=0', # pick a port. XXX: we may want to use --remote-debugging-pipe instead
- '--homepage=about:blank',
- 'about:blank']
- # start new session, so ^C does not affect subprocess
- self.p = subprocess.Popen (args, start_new_session=True,
- stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
- stderr=subprocess.DEVNULL)
- port = None
- # chrome writes its current active devtools port to a file. due to the
- # sleep() this is rather ugly, but should work with all versions of the
- # browser.
- for i in range (100):
- try:
- with open (os.path.join (self.userDataDir, 'DevToolsActivePort'), 'r') as fd:
- port = int (fd.readline ().strip ())
- break
- except FileNotFoundError:
- time.sleep (0.2)
- if port is None:
- raise Exception ('Chrome died on us.')
-
- return 'http://localhost:{}'.format (port)
-
- def __exit__ (self, *exc):
- self.p.terminate ()
- self.p.wait ()
- shutil.rmtree (self.userDataDir)
- self.p = None
- return False
-
-class NullService:
- __slots__ = ('url')
-
- def __init__ (self, url):
- self.url = url
-
- def __enter__ (self):
- return self.url
-
- def __exit__ (self, *exc):
- return False
-