async def create(client: CDPSession, target: 'Target', ignoreHTTPSErrors: bool = False, appMode: bool = False, screenshotTaskQueue: list = None) -> 'Page': """Async function which makes new page object.""" await client.send('Page.enable'), frameTree = (await client.send('Page.getFrameTree'))['frameTree'] page = Page(client, target, frameTree, ignoreHTTPSErrors, screenshotTaskQueue) await asyncio.wait([ client.send('Page.setLifecycleEventsEnabled', {'enabled': True}), client.send('Network.enable', {}), client.send('Runtime.enable', {}), client.send('Security.enable', {}), client.send('Performance.enable', {}), ]) if ignoreHTTPSErrors: await client.send('Security.setOverrideCertificateErrors', {'override': True}) if not appMode: await page.setViewport({'width': 800, 'height': 600}) return page
def releaseObject(client: CDPSession, remoteObject: dict) -> Awaitable: """Release remote object.""" objectId = remoteObject.get('objectId') fut_none = client._loop.create_future() fut_none.set_result(None) if not objectId: return fut_none try: return client.send('Runtime.releaseObject', {'objectId': objectId}) except Exception as e: # Exceptions might happen in case of a page been navigated or closed. # Swallow these since they are harmless and we don't leak anything in this case. # noqa debugError(logger, e) return fut_none
def releaseObject(client: CDPSession, remoteObject: dict) -> Awaitable: 'Release remote object.' objectId = remoteObject.get('objectId') fut_none = client._loop.create_future() fut_none.set_result(None) if (not objectId): return fut_none try: return client.send('Runtime.releaseObject', { 'objectId': objectId, }) except Exception as e: debugError(logger, e) return fut_none
def releaseObject(client: CDPSession, remoteObject: dict ) -> Awaitable: """Release remote object.""" objectId = remoteObject.get('objectId') fut_none = client._loop.create_future() fut_none.set_result(None) if not objectId: return fut_none try: return client.send('Runtime.releaseObject', { 'objectId': objectId }) except Exception as e: # Exceptions might happen in case of a page been navigated or closed. # Swallow these since they are harmless and we don't leak anything in this case. # noqa debugError(logger, e) return fut_none
def __init__(self, client: CDPSession, frameTree: Dict, page: Any) -> None: """Make new frame manager.""" super().__init__() self._client = client self._page = page self._frames: OrderedDict[str, Frame] = OrderedDict() self._mainFrame: Optional[Frame] = None self._contextIdToContext: Dict[str, ExecutionContext] = dict() client.on('Page.frameAttached', lambda event: self._onFrameAttached( event.get('frameId', ''), event.get('parentFrameId', '')) ) client.on('Page.frameNavigated', lambda event: self._onFrameNavigated(event.get('frame'))) client.on('Page.navigatedWithinDocument', lambda event: self._onFrameNavigatedWithinDocument( event.get('frameId'), event.get('url') )) client.on('Page.frameDetached', lambda event: self._onFrameDetached(event.get('frameId'))) client.on('Page.frameStoppedLoading', lambda event: self._onFrameStoppedLoading( event.get('frameId') )) client.on('Runtime.executionContextCreated', lambda event: self._onExecutionContextCreated( event.get('context'))) client.on('Runtime.executionContextDestroyed', lambda event: self._onExecutionContextDestroyed( event.get('executionContextId'))) client.on('Runtime.executionContextsCleared', lambda event: self._onExecutionContextsCleared()) client.on('Page.lifecycleEvent', lambda event: self._onLifecycleEvent(event)) self._handleFrameTree(frameTree)
def __init__(self, client: CDPSession, frameTree: Dict, page: Any) -> None: """Make new frame manager.""" super().__init__() self._client = client self._page = page self._frames: OrderedDict[str, Frame] = OrderedDict() self._mainFrame: Optional[Frame] = None self._contextIdToContext: Dict[str, ExecutionContext] = dict() client.on('Page.frameAttached', lambda event: self._onFrameAttached( event.get('frameId', ''), event.get('parentFrameId', '')) ) client.on('Page.frameNavigated', lambda event: self._onFrameNavigated(event.get('frame'))) client.on('Page.frameDetached', lambda event: self._onFrameDetached(event.get('frameId'))) client.on('Runtime.executionContextCreated', lambda event: self._onExecutionContextCreated( event.get('context'))) client.on('Runtime.executionContextDestroyed', lambda event: self._onExecutionContextDestroyed( event.get('executionContextId'))) client.on('Runtime.executionContextsCleared', lambda event: self._onExecutionContextsCleared()) client.on('Page.lifecycleEvent', lambda event: self._onLifecycleEvent(event)) self._handleFrameTree(frameTree)
def __init__(self, client: CDPSession, frameTree: Dict, page: Any) -> None: 'Make new frame manager.' super().__init__() self._client = client self._page = page self._frames = OrderedDict() self._mainFrame = None self._contextIdToContext = dict() client.on('Page.frameAttached', (lambda event: self._onFrameAttached( event.get('frameId', ''), event.get('parentFrameId', '')))) client.on('Page.frameNavigated', (lambda event: self._onFrameNavigated(event.get('frame')))) client.on('Page.navigatedWithinDocument', (lambda event: self._onFrameNavigatedWithinDocument( event.get('frameId'), event.get('url')))) client.on('Page.frameDetached', (lambda event: self._onFrameDetached(event.get('frameId')))) client.on( 'Page.frameStoppedLoading', (lambda event: self._onFrameStoppedLoading(event.get('frameId')))) client.on('Runtime.executionContextCreated', (lambda event: self._onExecutionContextCreated( event.get('context')))) client.on('Runtime.executionContextDestroyed', (lambda event: self._onExecutionContextDestroyed( event.get('executionContextId')))) client.on('Runtime.executionContextsCleared', (lambda event: self._onExecutionContextsCleared())) client.on('Page.lifecycleEvent', (lambda event: self._onLifecycleEvent(event))) self._handleFrameTree(frameTree)
def __init__(self, client: CDPSession, target: 'Target', frameTree: Dict, ignoreHTTPSErrors: bool = False, screenshotTaskQueue: list = None, ) -> None: super().__init__() self._client = client self._target = target self._keyboard = Keyboard(client) self._mouse = Mouse(client, self._keyboard) self._touchscreen = Touchscreen(client, self._keyboard) self._frameManager = FrameManager(client, frameTree, self) self._networkManager = NetworkManager(client, self._frameManager) self._emulationManager = EmulationManager(client) self._tracing = Tracing(client) self._pageBindings: Dict[str, Callable] = dict() self._ignoreHTTPSErrors = ignoreHTTPSErrors self._defaultNavigationTimeout = 30000 # milliseconds self._coverage = Coverage(client) if screenshotTaskQueue is None: screenshotTaskQueue = list() self._screenshotTaskQueue = screenshotTaskQueue _fm = self._frameManager _fm.on(FrameManager.Events.FrameAttached, lambda event: self.emit(Page.Events.FrameAttached, event)) _fm.on(FrameManager.Events.FrameDetached, lambda event: self.emit(Page.Events.FrameDetached, event)) _fm.on(FrameManager.Events.FrameNavigated, lambda event: self.emit(Page.Events.FrameNavigated, event)) _nm = self._networkManager _nm.on(NetworkManager.Events.Request, lambda event: self.emit(Page.Events.Request, event)) _nm.on(NetworkManager.Events.Response, lambda event: self.emit(Page.Events.Response, event)) _nm.on(NetworkManager.Events.RequestFailed, lambda event: self.emit(Page.Events.RequestFailed, event)) _nm.on(NetworkManager.Events.RequestFinished, lambda event: self.emit(Page.Events.RequestFinished, event)) client.on('Page.loadEventFired', lambda event: self.emit(Page.Events.Load)) client.on('Runtime.consoleAPICalled', lambda event: self._onConsoleAPI(event)) client.on('Page.javascriptDialogOpening', lambda event: self._onDialog(event)) client.on('Runtime.exceptionThrown', lambda exception: self._handleException( exception.get('exceptionDetails'))) client.on('Security.certificateError', lambda event: self._onCertificateError(event)) client.on('Inspector.targetCrashed', lambda event: self._onTargetCrashed()) client.on('Performance.metrics', lambda event: self._emitMetrics(event))
def __init__( self, client: CDPSession, target: 'Target', frameTree: Dict, ignoreHTTPSErrors: bool = False, screenshotTaskQueue: list = None, ) -> None: super().__init__() self._client = client self._target = target self._keyboard = Keyboard(client) self._mouse = Mouse(client, self._keyboard) self._touchscreen = Touchscreen(client, self._keyboard) self._frameManager = FrameManager(client, frameTree, self) self._networkManager = NetworkManager(client, self._frameManager) self._emulationManager = EmulationManager(client) self._tracing = Tracing(client) self._pageBindings: Dict[str, Callable] = dict() self._ignoreHTTPSErrors = ignoreHTTPSErrors self._defaultNavigationTimeout = 30000 # milliseconds self._coverage = Coverage(client) if screenshotTaskQueue is None: screenshotTaskQueue = list() self._screenshotTaskQueue = screenshotTaskQueue _fm = self._frameManager _fm.on(FrameManager.Events.FrameAttached, lambda event: self.emit(Page.Events.FrameAttached, event)) _fm.on(FrameManager.Events.FrameDetached, lambda event: self.emit(Page.Events.FrameDetached, event)) _fm.on(FrameManager.Events.FrameNavigated, lambda event: self.emit(Page.Events.FrameNavigated, event)) _nm = self._networkManager _nm.on(NetworkManager.Events.Request, lambda event: self.emit(Page.Events.Request, event)) _nm.on(NetworkManager.Events.Response, lambda event: self.emit(Page.Events.Response, event)) _nm.on(NetworkManager.Events.RequestFailed, lambda event: self.emit(Page.Events.RequestFailed, event)) _nm.on(NetworkManager.Events.RequestFinished, lambda event: self.emit(Page.Events.RequestFinished, event)) client.on('Page.loadEventFired', lambda event: self.emit(Page.Events.Load)) client.on('Runtime.consoleAPICalled', lambda event: self._onConsoleAPI(event)) client.on('Page.javascriptDialogOpening', lambda event: self._onDialog(event)) client.on( 'Runtime.exceptionThrown', lambda exception: self._handleException( exception.get('exceptionDetails'))) client.on('Security.certificateError', lambda event: self._onCertificateError(event)) client.on('Inspector.targetCrashed', lambda event: self._onTargetCrashed()) client.on('Performance.metrics', lambda event: self._emitMetrics(event))
def __init__(self, client: CDPSession, page: Any, ignoreHTTPSErrors) -> None: """Make new frame manager.""" super().__init__() self._client = client self._page = page self._networkmanager = NetworkManager(client, self, ignoreHTTPSErrors) self._frames: OrderedDict[str, Frame] = OrderedDict() self._mainFrame: Optional[Frame] = None self._contextIdToContext: Dict[str, ExecutionContext] = dict() self._isolatedWorlds = set() client.on( 'Page.frameAttached', lambda event: self._onFrameAttached( event.get('frameId', ''), event.get('parentFrameId', ''))) client.on('Page.frameNavigated', lambda event: self._onFrameNavigated(event.get('frame'))) client.on( 'Page.navigatedWithinDocument', lambda event: self._onFrameNavigatedWithinDocument( event.get('frameId'), event.get('url'))) client.on('Page.frameDetached', lambda event: self._onFrameDetached(event.get('frameId'))) client.on( 'Page.frameStoppedLoading', lambda event: self._onFrameStoppedLoading(event.get('frameId'))) client.on( 'Runtime.executionContextCreated', lambda event: self. _onExecutionContextCreated(event.get('context'))) client.on( 'Runtime.executionContextDestroyed', lambda event: self._onExecutionContextDestroyed( event.get('executionContextId'))) client.on('Runtime.executionContextsCleared', lambda event: self._onExecutionContextsCleared()) client.on('Page.lifecycleEvent', lambda event: self._onLifecycleEvent(event))