def __init__(self, endpoint): self.loop = asyncio.new_event_loop() self.endpoint = endpoint self.browser = self.run_until_complete( connect(browserWSEndpoint=self.endpoint, loop=self.loop)) CONTEXT_POOL.append(self)
def test_open_headless_browser(self): """ Opens a headless browser, checks if it is open and closes it """ run(['python3', 'screamshot/browser_manager_script.py', '-o', '-ns']) endpoint = get_endpoint() browser = to_sync(connect({'browserWSEndpoint': endpoint})) self.assertIsInstance(browser, Browser) run(['python3', 'screamshot/browser_manager_script.py', '-c'])
def get_browser(self, pyppeteer_args=None): if pyppeteer_args is None: pyppeteer_args = {} if not hasattr(self, "_browser"): self.loop = asyncio.get_event_loop() browser_args = {'headless': True, 'args': ['--no-sandbox']} browser_args.update(pyppeteer_args) if 'browserWSEndpoint' in browser_args: self._browser = self.loop.run_until_complete( pyppeteer.connect(**browser_args)) else: self._browser = self.loop.run_until_complete( pyppeteer.launch(**browser_args)) return self._browser
def __init__(self): # option = webdriver.ChromeOptions() # for arg in DEFAULT_ARGS: # option.add_argument(arg) # self.browser = webdriver.Remote( # command_executor=ChromeRemoteConnection( # remote_server_addr='http://127.0.0.1:48192', # keep_alive=True # ), # desired_capabilities=option.to_capabilities() # ) base = 'http://127.0.0.1:21218' data = requests.get(f'{base}/json/version').json() self.browser = loop.run_until_complete( connect(browserWSEndpoint=data['webSocketDebuggerUrl'], logLevel='WARNING'))
import asyncio import argparse import requests from pyppeteer import connect from pyppeteer.browser import Browser from pyppeteer.page import Page loop = asyncio.get_event_loop() base = 'http://127.0.0.1:21218' data = requests.get(f'{base}/json/version').json() browser: Browser = loop.run_until_complete( connect(browserWSEndpoint=data['webSocketDebuggerUrl'], logLevel='WARNING')) async def show_tabs_command(): for tab in await browser.pages(): print('%r, %r' % (tab.url, await tab.title())) async def page_source_command(): for tab in await browser.pages(): print('%r' % tab.url) print('%r' % await tab.content()) print('\n==============================\n') async def main(): parser = argparse.ArgumentParser( description='Control RWCTF Crawlbox Game.')