Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# dont forget to close browser process
atexit.register(_close_process)
if self.options.get('handleSIGINT', True):
signal.signal(signal.SIGINT, _close_process)
if self.options.get('handleSIGTERM', True):
signal.signal(signal.SIGTERM, _close_process)
if not sys.platform.startswith('win'):
# SIGHUP is not defined on windows
if self.options.get('handleSIGHUP', True):
signal.signal(signal.SIGHUP, _close_process)
connectionDelay = self.options.get('slowMo', 0)
self.browserWSEndpoint = self._get_ws_endpoint()
self.connection = Connection(self.browserWSEndpoint, connectionDelay)
return await Browser.create(
self.connection, self.options, self.proc, self.killChrome)
if logLevel:
logging.getLogger('pyppeteer').setLevel(logLevel)
browserWSEndpoint = options.get('browserWSEndpoint')
if not browserWSEndpoint:
raise BrowserError('Need `browserWSEndpoint` option.')
connectionDelay = options.get('slowMo', 0)
connection = Connection(browserWSEndpoint,
options.get('loop', asyncio.get_event_loop()),
connectionDelay)
browserContextIds = (await connection.send('Target.getBrowserContexts')
).get('browserContextIds', [])
ignoreHTTPSErrors = bool(options.get('ignoreHTTPSErrors', False))
defaultViewport = options.get('defaultViewport',
{'width': 800, 'height': 600})
return await Browser.create(
connection, browserContextIds, ignoreHTTPSErrors, defaultViewport,
None, lambda: connection.send('Browser.close'))
async def launch(self):
self.chromeClosed = False
self.connection = None
env = self.options.get("env")
self.proc = await asyncio.subprocess.create_subprocess_exec(
*self.cmd,
stdout=asyncio.subprocess.DEVNULL,
stderr=asyncio.subprocess.DEVNULL,
env=env,
)
# Signal handlers for exits used to be here
connectionDelay = self.options.get("slowMo", 0)
self.browserWSEndpoint = await self._get_ws_endpoint()
self.connection = Connection(
self.browserWSEndpoint, self._loop, connectionDelay)
return await Browser.create(
self.connection, self.options, self.proc, self.killChrome)
if self.handleSIGTERM:
signal.signal(signal.SIGTERM, _close_process)
if not sys.platform.startswith('win'):
# SIGHUP is not defined on windows
if self.handleSIGHUP:
signal.signal(signal.SIGHUP, _close_process)
connectionDelay = self.slowMo
self.browserWSEndpoint = self._get_ws_endpoint()
logger.info(f'Browser listening on: {self.browserWSEndpoint}')
self.connection = Connection(
self.browserWSEndpoint,
self._loop,
connectionDelay,
)
browser = await Browser.create(
self.connection, [], self.ignoreHTTPSErrors, self.defaultViewport,
self.proc, self.killChrome)
await self.ensureInitialPage(browser)
return browser
# dont forget to close browser process
atexit.register(_close_process)
if self.options.get("handleSIGINT", True):
signal.signal(signal.SIGINT, _close_process)
if self.options.get("handleSIGTERM", True):
signal.signal(signal.SIGTERM, _close_process)
if not sys.platform.startswith("win"):
# SIGHUP is not defined on windows
if self.options.get("handleSIGHUP", True):
signal.signal(signal.SIGHUP, _close_process)
connectionDelay = self.options.get("slowMo", 0)
self.browserWSEndpoint = self._get_ws_endpoint()
self.connection = Connection(self.browserWSEndpoint, connectionDelay)
return await Browser.create(
self.connection, self.options, self.proc, self.killChrome
)