Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_async_browser_session():
session = AsyncHTMLSession()
browser = await session.browser
assert isinstance(browser, Browser)
await session.close()
def test_browser_session():
""" Test browser instaces is created and properly close when session is closed.
Note: session.close method need to be tested together with browser creation,
since no doing that will left the browser running. """
session = HTMLSession()
assert isinstance(session.browser, Browser)
assert hasattr(session, "loop") == True
session.close()
# assert count_chromium_process() == 0
async def _targetInfoChanged(self, event: Dict) -> None:
target = self._targets.get(event['targetInfo']['targetId'])
if not target:
raise BrowserError('target should exist before targetInfoChanged')
previousURL = target.url
wasInitialized = target._isInitialized
target._targetInfoChanged(event['targetInfo'])
if wasInitialized and previousURL != target.url:
self.emit(Browser.Events.TargetChanged, target)
target.browserContext.emit(BrowserContext.Events.TargetChanged, target) # noqa: E501
async def create(connection: Connection, contextIds: List[str],
ignoreHTTPSErrors: bool, defaultViewport: Optional[Dict],
process: Optional[Popen] = None,
closeCallback: Callable[[], Awaitable[None]] = None,
**kwargs: Any) -> 'Browser':
"""Create browser object."""
browser = Browser(connection, contextIds, ignoreHTTPSErrors,
defaultViewport, process, closeCallback)
await connection.send('Target.setDiscoverTargets', {'discover': True})
return browser
def __init__(self, settings: Settings):
self._browser: Optional[Browser] = None
self._launch_options = settings.getdict('PYPPETEER_LAUNCH') or {}