### Complete nodriver Example Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/quickstart A more comprehensive example showcasing advanced nodriver features such as taking screenshots, getting page content, scrolling, selecting elements, opening new tabs and windows, and managing them. ```python import nodriver async def main(): browser = await nodriver.start() page = await browser.get('https://www.nowsecure.nl') await page.save_screenshot() await page.get_content() await page.scroll_down(150) elems = await page.select_all('*[src]') for elem in elems: await elem.flash() page2 = await browser.get('https://twitter.com', new_tab=True) page3 = await browser.get('https://github.com/ultrafunkamsterdam/nodriver', new_window=True) for p in (page, page2, page3): await p.bring_to_front() await p.scroll_down(200) await p # wait for events to be processed await p.reload() if p != page3: await p.close() if __name__ == '__main__': # since asyncio.run never worked (for me) uc.loop().run_until_complete(main()) ``` -------------------------------- ### Basic nodriver Usage Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/quickstart A simple example demonstrating how to start a browser instance, navigate to a URL, and perform basic actions using nodriver. It utilizes Python's asyncio for asynchronous operations. ```python import nodriver as uc async def main(): browser = await uc.start() page = await browser.get('https://www.nowsecure.nl') ... further code ... if __name__ == '__main__': # since asyncio.run never worked (for me) uc.loop().run_until_complete(main()) ``` -------------------------------- ### install Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/cdp/pwa Installs the given manifest identity, optionally using a provided install URL or bundle URL. ```APIDOC ## POST /install ### Description Installs the given manifest identity, optionally using a provided install URL or bundle URL. Supports IWA and file installation modes. ### Method POST ### Endpoint /install ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **manifest_id** (str) - Required - The manifest identity of the app to install. - **install_url_or_bundle_url** (Optional[str]) - Optional - The location of the app or bundle overriding the one derived from the manifestId. Can be a file:// or http(s):// URL. ### Request Example ```json { "manifest_id": "isolated-app://some-web-bundle-id", "install_url_or_bundle_url": "file:///path/to/app.swbn" } ``` ### Response #### Success Response (200) - **None** (None) - Indicates successful installation. #### Response Example ```json null ``` ``` -------------------------------- ### PWA Installation API Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/pwa Installs a PWA using its manifest ID. Optionally, an install URL or bundle URL can be provided to override the default installation source. Supports file-based and dev proxy installation modes. ```APIDOC ## PWA Install ### Description Installs the given manifest identity, optionally using the given installUrlOrBundleUrl. Supports file and dev proxy installation modes. ### Method POST ### Endpoint /pwa/install ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **manifestId** (string) - Required - The id from the webapp's manifest file. - **installUrlOrBundleUrl** (string) - Optional - The location of the app or bundle overriding the one derived from the manifestId. ### Request Example ```json { "manifestId": "isolated-app://your-app-id", "installUrlOrBundleUrl": "https://example.com/your-app.swbn" } ``` ### Response #### Success Response (200) - **None** - Indicates successful installation. #### Response Example (No response body on success) ``` -------------------------------- ### Launch Installed Web App - Python Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/pwa Launches an installed web app. It can optionally open a specific URL within the app instead of the default start URL. This function returns a TargetID that can be used to attach to the created tab. ```python def launch( manifest_id: str, url: typing.Optional[str] = None ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,target.TargetID]: ''' Launches the installed web app, or an url in the same web app instead of the default start url if it is provided. Returns a page Target.TargetID which can be used to attach to via Target.attachToTarget or similar APIs. :param manifest_id: :param url: *(Optional)* :returns: ID of the tab target created as a result. ''' params: T_JSON_DICT = dict() params['manifestId'] = manifest_id if url is not None: params['url'] = url cmd_dict: T_JSON_DICT = { 'method': 'PWA.launch', 'params': params, } json = yield cmd_dict return target.TargetID.from_json(json['targetId']) ``` -------------------------------- ### Basic nodriver Browser Automation Source: https://ultrafunkamsterdam.github.io/nodriver/readme This snippet demonstrates fundamental nodriver functionalities such as starting a browser, navigating to a URL, taking a screenshot, getting page content, scrolling, selecting elements, and opening new tabs/windows. ```python import asyncio import nodriver as uc async def main(): browser = await uc.start() page = await browser.get('https://www.nowsecure.nl') await page.save_screenshot() await page.get_content() await page.scroll_down(150) elems = await page.select_all('*[src]') for elem in elems: await elem.flash() page2 = await browser.get('https://twitter.com', new_tab=True) page3 = await browser.get('https://github.com/ultrafunkamsterdam/nodriver', new_window=True) for p in (page, page2, page3): await p.bring_to_front() await p.scroll_down(200) await p # wait for events to be processed await p.reload() if p != page3: await p.close() if __name__ == '__main__': # since asyncio.run never worked (for me) uc.loop().run_until_complete(main()) ``` -------------------------------- ### Install nodriver Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/quickstart Instructions for installing the nodriver package using pip. It can be installed directly or as part of the undetected-chromedriver package. ```bash pip install undetected-chromedriver ``` ```bash pip install nodriver ``` -------------------------------- ### Start Browser Instance with Configuration Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/core/browser This method launches a new browser instance or connects to an existing one. It handles configuration, checks for the browser executable path, and sets up the necessary parameters for starting the browser process. It uses `asyncio` for subprocess management and `pathlib` for file path operations. ```python if not connect_existing: logger.debug( "BROWSER EXECUTABLE PATH: %s", self.config.browser_executable_path ) if not pathlib.Path(self.config.browser_executable_path).exists(): raise FileNotFoundError( ( """ --------------------- Could not determine browser executable. --------------------- Make sure your browser is installed in the default location (path). If you are sure about the browser executable, you can specify it using the `browser_executable_path='{}` parameter.""" ).format( "/path/to/browser/executable" if is_posix else "c:/path/to/your/browser.exe" ) ) if getattr(self.config, "_extensions", None): # noqa self.config.add_argument( "--load-extension=%s" % ",".join(str(_) for _ in self.config._extensions) # noqa ) exe = self.config.browser_executable_path params = self.config() logger.info( "starting\n\texecutable :%s\n\narguments:\n%s", exe, "\n\t".join(params) ) if not connect_existing: self._process: asyncio.subprocess.Process = ( await asyncio.create_subprocess_exec( exe, *params, stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, close_fds=is_posix, ) ) self._process_pid = self._process.pid self._http = HTTPApi((self.config.host, self.config.port)) util.get_registered_instances().add(self) await asyncio.sleep(0.25) for _ in range(5): try: self.info = ContraDict(await self._http.get("version"), silent=True) except (Exception,): if _ == 4: logger.debug("could not start", exc_info=True) await self.sleep(0.5) else: break ``` -------------------------------- ### start(_categories =None_, _options =None_, _buffer_usage_reporting_interval =None_, _transfer_mode =None_, _stream_format =None_, _stream_compression =None_, _trace_config =None_, _perfetto_config =None_, _tracing_backend =None_) Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/cdp/tracing Starts trace events collection with various configuration options. Supports deprecated categories/options and EXPERIMENTAL settings for buffer usage reporting, transfer mode, stream format, and compression. ```APIDOC ## start(_categories =None_, _options =None_, _buffer_usage_reporting_interval =None_, _transfer_mode =None_, _stream_format =None_, _stream_compression =None_, _trace_config =None_, _perfetto_config =None_, _tracing_backend =None_) ### Description Start trace events collection. ### Method Generator ### Endpoint N/A (Command function) ### Parameters #### Query Parameters - **categories** (Optional[str]) - DEPRECATED, EXPERIMENTAL, Optional - Category/tag filter - **options** (Optional[str]) - DEPRECATED, EXPERIMENTAL, Optional - Tracing options - **buffer_usage_reporting_interval** (Optional[float]) - EXPERIMENTAL, Optional - If set, the agent will issue bufferUsage events at this interval, specified in milliseconds - **transfer_mode** (Optional[str]) - Optional - Whether to report trace events as series of dataCollected events or to save trace to a stream (defaults to `ReportEvents`) - **stream_format** (Optional[StreamFormat]) - Optional - Trace data format to use. This only applies when using `ReturnAsStream` transfer mode (defaults to `json`). - **stream_compression** (Optional[StreamCompression]) - EXPERIMENTAL, Optional - Compression format to use. This only applies when using `ReturnAsStream` transfer mode (defaults to `none`). - **trace_config** (Optional[TraceConfig]) - Optional - **perfetto_config** (Optional[str]) - EXPERIMENTAL, Optional - Base64-encoded serialized perfetto.protos.TraceConfig protobuf message. When specified, the parameters `categories`, `options`, `traceConfig` are ignored. (Encoded as a base64 string when passed over JSON) - **tracing_backend** (Optional[TracingBackend]) - EXPERIMENTAL, Optional - Backend type (defaults to `auto`) ### Request Example ```json { "categories": "[\"test_category\", \"another\"]", "buffer_usage_reporting_interval": 1000, "transfer_mode": "ReturnAsStream", "stream_format": "json", "stream_compression": "gzip", "perfetto_config": "aGVsbG8=" } ``` ### Response #### Success Response (Generator Return) - **type**: `None` #### Response Example ```json null ``` ``` -------------------------------- ### Install PWA Function (Python) Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/pwa Installs a PWA identified by its manifest ID. It supports installing from a provided URL or bundle URL, and includes specific modes for IWA, file, and dev proxy installations. ```python from __future__ import annotations import enum import typing from dataclasses import dataclass from .util import event_class, T_JSON_DICT from . import target def install( manifest_id: str, install_url_or_bundle_url: typing.Optional[str] = None ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]: ''' Installs the given manifest identity, optionally using the given installUrlOrBundleUrl IWA-specific install description: manifestId corresponds to isolated-app:// + web_package::SignedWebBundleId File installation mode: The installUrlOrBundleUrl can be either file:// or http(s):// pointing to a signed web bundle (.swbn). In this case SignedWebBundleId must correspond to The .swbn file's signing key. Dev proxy installation mode: installUrlOrBundleUrl must be http(s):// that serves dev mode IWA. web_package::SignedWebBundleId must be of type dev proxy. The advantage of dev proxy mode is that all changes to IWA automatically will be reflected in the running app without reinstallation. To generate bundle id for proxy mode: 1. Generate 32 random bytes. 2. Add a specific suffix at the end following the documentation https://github.com/WICG/isolated-web-apps/blob/main/Scheme.md#suffix 3. Encode the entire sequence using Base32 without padding. If Chrome is not in IWA dev mode, the installation will fail, regardless of the state of the allowlist. :param manifest_id: :param install_url_or_bundle_url: *(Optional)* The location of the app or bundle overriding the one derived from the manifestId. '* params: T_JSON_DICT = dict() params['manifestId'] = manifest_id if install_url_or_bundle_url is not None: params['installUrlOrBundleUrl'] = install_url_or_bundle_url cmd_dict: T_JSON_DICT = { 'method': 'PWA.install', 'params': params, } json = yield cmd_dict ``` -------------------------------- ### Instantiate Browser using create() - Python Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/classes/browser The `Browser.create()` method is the asynchronous entry point for instantiating a Browser object. It allows configuration of various browser settings like headless mode, executable path, and arguments. It returns a Browser instance, which then needs to be started using the `start()` method. ```python import nodriver async def main(): browser = await nodriver.Browser.create(headless=True) await browser.start() # ... use browser instance ... await browser.stop() # To run this async function # import asyncio # asyncio.run(main()) ``` -------------------------------- ### Browser Download Will Begin Event (Python) Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/browser Represents an event fired when a page is about to start a download. This experimental event provides the frame ID that initiated the download, a unique download GUID, the download URL, and a suggested file name. ```python @event_class('Browser.downloadWillBegin') @dataclass class DownloadWillBegin: ''' **EXPERIMENTAL** Fired when page is about to start a download. ''' #: Id of the frame that caused the download to begin. frame_id: page.FrameId #: Global unique identifier of the download. guid: str #: URL of the resource being downloaded. url: str #: Suggested file name of the resource (the actual name of the file saved on disk may differ). ``` -------------------------------- ### start_sampling Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/cdp/heap_profiler Starts sampling the heap with optional interval and GC inclusion settings. ```APIDOC ## start_sampling ### Description Starts sampling the heap with specified parameters. ### Method Not specified (likely internal command) ### Endpoint Not applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "method": "start_sampling", "params": { "samplingInterval": 32768, "includeObjectsCollectedByMajorGC": false, "includeObjectsCollectedByMinorGC": false } } ``` ### Response #### Success Response (200) Type: Generator[Dict[str, Any], Dict[str, Any], None] #### Response Example ```json null ``` ``` -------------------------------- ### Get Installability Errors Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/cdp/page Retrieves a list of installability errors for the current application. This is an experimental feature. ```APIDOC ## POST /getInstallabilityErrors ### Description **EXPERIMENTAL** ### Method POST ### Endpoint /getInstallabilityErrors ### Parameters None ### Request Body None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **List[InstallabilityError]** - A list of installability errors. #### Response Example ```json { "result": [ { "errorId": "manifest-missing-id", "error":"Manifest is missing 'id' member.", "reason":"Manifest is missing required member.", "metadata": {} } ] } ``` ``` -------------------------------- ### Get Installability Errors - Python Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/page Retrieves a list of installability errors for the current page. This method is experimental and returns a list of InstallabilityError objects. It requires a JSON dictionary as input and yields a command dictionary. ```python def get_installability_errors() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[InstallabilityError]]: ''' **EXPERIMENTAL** :returns: ''' cmd_dict: T_JSON_DICT = { 'method': 'Page.getInstallabilityErrors', } json = yield cmd_dict return [InstallabilityError.from_json(i) for i in json['installabilityErrors']] ``` -------------------------------- ### nodriver Custom Start Options Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/quickstart Demonstrates how to customize the browser startup behavior in nodriver by providing options such as headless mode, user data directory, browser executable path, and specific browser arguments. ```python from nodriver import * browser = await start( headless=False, user_data_dir="/path/to/existing/profile", # by specifying it, it won't be automatically cleaned up when finished browser_executable_path="/path/to/some/other/browser", browser_args=['--some-browser-arg=true', '--some-other-option'], lang="en-US" # this could set iso-language-code in navigator, not recommended to change ) tab = await browser.get('https://somewebsite.com') ``` -------------------------------- ### GET /manifest-icons Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/cdp/page Retrieves icons associated with the website's manifest. Note: This is deprecated as the returned icon is not guaranteed to be the one used for PWA installation. ```APIDOC ## GET /manifest-icons ### Description Deprecated because it’s not guaranteed that the returned icon is in fact the one used for PWA installation. Deprecated since version 1.3. **EXPERIMENTAL** ### Method GET ### Endpoint /manifest-icons ### Response #### Success Response (200) - **Generator**[`Dict`[`str`, `Any`], `Dict`[`str`, `Any`], `Optional`[`str`]] - A generator yielding dictionaries of icon data, or an optional string. #### Response Example { "example": "(Generator yielding dictionaries of icon data or an optional string)" } ``` -------------------------------- ### Create a Browser Instance Asynchronously Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/core/browser The `create` class method is the entry point for instantiating the Browser object. It handles configuration and starts the browser process. It accepts various parameters to customize the browser session, such as user data directory, headless mode, and browser arguments. ```python instance = await Browser.create( user_data_dir="/path/to/user/data", headless=True, browser_executable_path="/path/to/chrome", browser_args=["--disable-gpu", "--no-sandbox"] ) ``` -------------------------------- ### Python: Get Possible Breakpoint Locations Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/cdp/debugger Retrieves a list of possible locations where a breakpoint can be set within a specified script range. It can optionally restrict results to the same function as the start location. ```python def get_possible_breakpoints(_start_ , _end =None_, _restrict_to_function =None_): """ Returns possible locations for breakpoint. scriptId in start and end range locations should be the same. Parameters: start (Location): Start of range to search possible breakpoint locations in. end (Optional[Location]): (Optional) End of range to search possible breakpoint locations in (excluding). When not specified, end of scripts is used as end of range. restrict_to_function (Optional[bool]): (Optional) Only consider locations which are in the same (non-nested) function as start. Return type: Generator[Dict[str, Any], Dict[str, Any], List[BreakLocation]] """ pass ``` -------------------------------- ### CSS.forceStartingStyle Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/css Ensures that the given node is in its starting-style state. ```APIDOC ## POST /CSS.forceStartingStyle ### Description Ensures that the given node is in its starting-style state. ### Method POST ### Endpoint /CSS.forceStartingStyle ### Parameters #### Query Parameters - **nodeId** (NodeId) - Required - The element ID for which to force the starting-style state. - **forced** (Boolean) - Required - Boolean indicating if this is on or off. ### Response #### Success Response (200) No specific fields in the response. #### Response Example ```json { "result": null } ``` ``` -------------------------------- ### Connect to Browser and Set Up Target Discovery (Python) Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/core/browser Establishes a connection to the browser and configures automatic discovery of browser targets. It handles potential connection errors, such as running as root without the `no_sandbox` option. Dependencies include the `cdp` library. ```python if not self.info: raise Exception( ( """ --------------------- Failed to connect to browser --------------------- One of the causes could be when you are running as root. In that case you need to pass no_sandbox=True """ ) ) self.connection = Connection(self.info.webSocketDebuggerUrl, browser=self) if self.config.autodiscover_targets: logger.info("enabling autodiscover targets") self.connection.handlers[cdp.target.TargetInfoChanged] = [ self._handle_target_update ] self.connection.handlers[cdp.target.TargetCreated] = [ self._handle_target_update ] self.connection.handlers[cdp.target.TargetDestroyed] = [ self._handle_target_update ] self.connection.handlers[cdp.target.TargetCrashed] = [ self._handle_target_update ] await self.connection.send(cdp.target.set_discover_targets(discover=True)) await self.update_targets() ``` -------------------------------- ### Get All-Time Memory Sampling Profile (Python) Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/memory Retrieves the native memory allocations profile collected since the renderer process started. It returns a 'SamplingProfile' object. This function generates a JSON-RPC command and processes the response. ```python def get_all_time_sampling_profile() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,SamplingProfile]: ''' Retrieve native memory allocations profile collected since renderer process startup. :returns: ''' cmd_dict: T_JSON_DICT = { 'method': 'Memory.getAllTimeSamplingProfile', } json = yield cmd_dict return SamplingProfile.from_json(json['profile']) ``` -------------------------------- ### Python: Parse DownloadWillBegin from JSON Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/page Parses a DownloadWillBegin event from a JSON dictionary. This event is fired when a page is about to start a download, providing the frame ID, download GUID, URL, and suggested filename. Note: This is deprecated in favor of Browser.downloadWillBegin. ```python from typing import Dict # Assuming FrameId and T_JSON_DICT are defined elsewhere class DownloadWillBegin: # ... (other attributes and methods) @classmethod def from_json(cls, json: T_JSON_DICT) -> 'DownloadWillBegin': return cls( frame_id=FrameId.from_json(json['frameId']), guid=str(json['guid']), url=str(json['url']), suggested_filename=str(json['suggestedFilename']) ) ``` -------------------------------- ### Drag Element to Destination (Python) Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/core/element Enables dragging an element to a specified destination, which can be another element or a coordinate pair. Supports relative dragging and specifies the number of steps for the drag action. Handles potential errors in getting start and end points. ```python async def mouse_drag( self, destination: typing.Union[Element, typing.Tuple[int, int]], relative: bool = False, steps: int = 1, ): """ drag an element to another element or target coordinates. dragging of elements should be supported by the site of course :param destination: another element where to drag to, or a tuple (x,y) of ints representing coordinate :type destination: Element or coordinate as x,y tuple :param relative: when True, treats coordinate as relative. for example (-100, 200) will move left 100px and down 200px :type relative: :param steps: move in points, this could make it look more "natural" (default 1), but also a lot slower. for very smooth action use 50-100 :type steps: int :return: :rtype: """ try: start_point = (await self.get_position()).center except AttributeError: return if not start_point: logger.warning("could not calculate box model for %s", self) return end_point = None if isinstance(destination, Element): try: end_point = (await destination.get_position()).center except AttributeError: return if not end_point: ``` -------------------------------- ### Start Tracing Command in Python Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/tracing This Python code constructs a dictionary representing the command to start tracing. It accepts various optional parameters like categories, options, buffer usage reporting interval, transfer mode, stream format, stream compression, trace configuration, perfetto configuration, and tracing backend. The method name and parameters are included in the resulting dictionary. ```python params: T_JSON_DICT = dict() if categories is not None: params['categories'] = categories if options is not None: params['options'] = options if buffer_usage_reporting_interval is not None: params['bufferUsageReportingInterval'] = buffer_usage_reporting_interval if transfer_mode is not None: params['transferMode'] = transfer_mode if stream_format is not None: params['streamFormat'] = stream_format.to_json() if stream_compression is not None: params['streamCompression'] = stream_compression.to_json() if trace_config is not None: params['traceConfig'] = trace_config.to_json() if perfetto_config is not None: params['perfettoConfig'] = perfetto_config if tracing_backend is not None: params['tracingBackend'] = tracing_backend.to_json() cmd_dict: T_JSON_DICT = { 'method': 'Tracing.start', 'params': params, } json = yield cmd_dict ``` -------------------------------- ### Get Manifest Icons - Python Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/page Fetches the primary manifest icon for the current page. This method is deprecated as of version 1.3 because the returned icon is not guaranteed to be the one used for PWA installation. It returns an optional string representing the icon URL. ```python @deprecated(version="1.3") def get_manifest_icons() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.Optional[str]]: ''' Deprecated because it's not guaranteed that the returned icon is in fact the one used for PWA installation. .. deprecated:: 1.3 **EXPERIMENTAL** :returns: ''' cmd_dict: T_JSON_DICT = { 'method': 'Page.getManifestIcons', } json = yield cmd_dict return str(json['primaryIcon']) if json.get('primaryIcon', None) is not None else None ``` -------------------------------- ### Browser Events Source: https://ultrafunkamsterdam.github.io/nodriver/index Documentation for browser-related events, including download progress and download initiation. ```APIDOC ## Browser Events API ### Description Handles events emitted by the browser, such as download progress and initiation. ### Events - **DownloadWillBegin** - `frame_id` (string) - `guid` (string) - `url` (string) - `suggested_filename` (string) - **DownloadProgress** - `guid` (string) - `total_bytes` (integer) - `received_bytes` (integer) - `state` (string) - `file_path` (string) ``` -------------------------------- ### Get Browser Sampling Profile (Python) Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/memory Retrieves the native memory allocations profile collected since the browser process started. It returns a 'SamplingProfile' object. This function constructs a JSON-RPC command and parses the returned profile data. ```python def get_browser_sampling_profile() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,SamplingProfile]: ''' Retrieve native memory allocations profile collected since browser process startup. :returns: ''' cmd_dict: T_JSON_DICT = { 'method': 'Memory.getBrowserSamplingProfile', } json = yield cmd_dict return SamplingProfile.from_json(json['profile']) ``` -------------------------------- ### Get Sampling Heap Profile (Python) Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/heap_profiler Retrieves the current sampling heap profile. This function is used after starting the sampling profiler to obtain the collected memory usage data. It returns a SamplingHeapProfile object containing detailed information about memory allocation. ```python def get_sampling_profile() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,SamplingHeapProfile]: ''' :returns: Return the sampling profile being collected. ''' cmd_dict: T_JSON_DICT = { 'method': 'HeapProfiler.getSamplingProfile', } json = yield cmd_dict return SamplingHeapProfile.from_json(json['profile']) ``` -------------------------------- ### CSS.startRuleUsageTracking Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/css Enables the selector recording. ```APIDOC ## POST /CSS.startRuleUsageTracking ### Description Enables the selector recording. ### Method POST ### Endpoint /CSS.startRuleUsageTracking ### Parameters None ### Request Example ```json { "method": "CSS.startRuleUsageTracking" } ``` ### Response #### Success Response (200) (No specific fields returned, indicates success) #### Response Example ```json {} ``` ``` -------------------------------- ### Highlighting Configurations Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/overlay Documentation for various highlighting configurations used for inspecting elements. ```APIDOC ## ContainerQueryContainerHighlightConfig ### Description A descriptor for the highlight appearance of container query containers. ### Fields - **containerQueryContainerHighlightConfig** (ContainerQueryContainerHighlightConfig) - Required - Configuration for container query container highlighting. - **nodeId** (dom.NodeId) - Required - Identifier of the container node to highlight. ### Request Example ```json { "containerQueryContainerHighlightConfig": { ... }, "nodeId": { ... } } ``` ### Response Example ```json { "containerQueryContainerHighlightConfig": { ... }, "nodeId": { ... } } ``` ## ContainerQueryContainerHighlightConfig ### Description Configuration for the highlight appearance of container query containers. ### Fields - **containerBorder** (LineStyle) - Optional - The style of the container border. - **descendantBorder** (LineStyle) - Optional - The style of the descendants' borders. ### Request Example ```json { "containerBorder": { ... }, "descendantBorder": { ... } } ``` ### Response Example ```json { "containerBorder": { ... }, "descendantBorder": { ... } } ``` ## IsolatedElementHighlightConfig ### Description A descriptor for the highlight appearance of an element in isolation mode. ### Fields - **isolationModeHighlightConfig** (IsolationModeHighlightConfig) - Required - Configuration for isolation mode highlighting. - **nodeId** (dom.NodeId) - Required - Identifier of the isolated element to highlight. ### Request Example ```json { "isolationModeHighlightConfig": { ... }, "nodeId": { ... } } ``` ### Response Example ```json { "isolationModeHighlightConfig": { ... }, "nodeId": { ... } } ``` ## IsolationModeHighlightConfig ### Description Configuration for the highlight appearance of an element in isolation mode. ### Fields - **resizerColor** (dom.RGBA) - Optional - The fill color of the resizers (default: transparent). - **resizerHandleColor** (dom.RGBA) - Optional - The fill color for resizer handles (default: transparent). - **maskColor** (dom.RGBA) - Optional - The fill color for the mask covering non-isolated elements (default: transparent). ### Request Example ```json { "resizerColor": { ... }, "resizerHandleColor": { ... }, "maskColor": { ... } } ``` ### Response Example ```json { "resizerColor": { ... }, "resizerHandleColor": { ... }, "maskColor": { ... } } ``` ``` -------------------------------- ### Take CSS Coverage Delta and Get Timestamp Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/css Retrieves a list of CSS rules that have become used since the last invocation of this method or since the start of coverage instrumentation. It also returns a monotonically increasing timestamp. This is useful for incremental analysis of CSS usage. ```python def take_coverage_delta() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.Tuple[typing.List[RuleUsage], float]]: ''' Obtain list of rules that became used since last call to this method (or since start of coverage instrumentation). :returns: A tuple with the following items: 0. **coverage** - 1. **timestamp** - Monotonically increasing time, in seconds. ''' cmd_dict: T_JSON_DICT = { 'method': 'CSS.takeCoverageDelta', } json = yield cmd_dict return ( [RuleUsage.from_json(i) for i in json['coverage']], float(json['timestamp']) ) ``` -------------------------------- ### Config Class Initialization and Methods Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/classes/others_and_helpers Initializes the Config object for browser automation. It allows customization of browser path, arguments, sandbox mode, language, and host/port settings. The add_extension method enables loading browser extensions. ```python class _Config(_user_data_dir =None_, _headless =False_, _browser_executable_path =None_, _browser_args =None_, _sandbox =True_, _lang ='en-US'_, _host =None_, _port =None_, _expert =None_, _** kwargs_): """Config object""" browser_args: user_data_dir: uses_custom_data_dir: bool def add_extension(_extension_path_): """adds an extension to load, you could point extension_path to a folder (containing the manifest), or extension file (crx) Parameters: extension_path (TypeVar(`PathLike`, bound= `str` | `Path`)): Returns: Return type: """ pass def add_argument(_arg_): pass ``` -------------------------------- ### BackgroundService Commands Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/cdp/background_service This section details the commands available for interacting with the BackgroundService. ```APIDOC ## POST /BackgroundService/clearEvents ### Description Clears all stored data for the specified background service. ### Method POST ### Endpoint /BackgroundService/clearEvents ### Parameters #### Query Parameters - **service** (ServiceName) - Required - The background service for which to clear data. ### Request Body ```json { "service": "backgroundFetch" } ``` ### Response #### Success Response (200) - **None** - This command does not return any data upon success. #### Response Example ```json {} ``` ``` ```APIDOC ## POST /BackgroundService/setRecording ### Description Configures the recording state for a specific background service. ### Method POST ### Endpoint /BackgroundService/setRecording ### Parameters #### Query Parameters - **should_record** (boolean) - Required - Whether to enable or disable recording. - **service** (ServiceName) - Required - The background service to configure. ### Request Body ```json { "should_record": true, "service": "pushMessaging" } ``` ### Response #### Success Response (200) - **None** - This command does not return any data upon success. #### Response Example ```json {} ``` ``` ```APIDOC ## POST /BackgroundService/startObserving ### Description Enables event updates for the specified background service. ### Method POST ### Endpoint /BackgroundService/startObserving ### Parameters #### Query Parameters - **service** (ServiceName) - Required - The background service for which to enable event updates. ### Request Body ```json { "service": "notifications" } ``` ### Response #### Success Response (200) - **None** - This command does not return any data upon success. #### Response Example ```json {} ``` ``` ```APIDOC ## POST /BackgroundService/stopObserving ### Description Disables event updates for the specified background service. ### Method POST ### Endpoint /BackgroundService/stopObserving ### Parameters #### Query Parameters - **service** (ServiceName) - Required - The background service for which to disable event updates. ### Request Body ```json { "service": "paymentHandler" } ``` ### Response #### Success Response (200) - **None** - This command does not return any data upon success. #### Response Example ```json {} ``` ``` -------------------------------- ### Get Search Results by Index (Python) Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/dom Retrieves a range of search results identified by a unique search ID. It requires the search ID, a starting index (from_index), and an ending index (to_index). The function returns a list of NodeIds corresponding to the found nodes. This is an experimental feature and part of the DOM.getSearchResults command. ```python def get_search_results( search_id: str, from_index: int, to_index: int ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,typing.List[NodeId]]: ''' Returns search results from given ``fromIndex`` to given ``toIndex`` from the search with the given identifier. **EXPERIMENTAL** :param search_id: Unique search session identifier. :param from_index: Start index of the search result to be returned. :param to_index: End index of the search result to be returned. :returns: Ids of the search result nodes. ''' params: T_JSON_DICT = dict() params['searchId'] = search_id params['fromIndex'] = from_index params['toIndex'] = to_index cmd_dict: T_JSON_DICT = { 'method': 'DOM.getSearchResults', 'params': params, } json = yield cmd_dict return [NodeId.from_json(i) for i in json['nodeIds']] ``` -------------------------------- ### launch Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/cdp/pwa Launches the installed web app, or a specific URL within the app if provided. Returns a Target.TargetID for attaching to the launched page. ```APIDOC ## POST /launch ### Description Launches the installed web app, or a specific URL within the app if provided. Returns a Target.TargetID for attaching to the launched page. ### Method POST ### Endpoint /launch ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **manifest_id** (str) - Required - The manifest ID of the web app to launch. - **url** (Optional[str]) - Optional - A specific URL within the web app to launch instead of the default start URL. ### Request Example ```json { "manifest_id": "some_manifest_id", "url": "/settings" } ``` ### Response #### Success Response (200) - **TargetID** (str) - The ID of the launched tab target. #### Response Example ```json "target_abc123" ``` ``` -------------------------------- ### Opening New Tabs and Windows Source: https://ultrafunkamsterdam.github.io/nodriver/readme Examples for opening a new tab with a specified URL and opening a new browser window with a specified URL. ```python from nodriver import browser async def main(): # Open URL in a new tab tab = await browser.get(url, new_tab=True) # Open URL in a new window tab_win = await browser.get(url, new_window=True) # To run the async function: # import asyncio # asyncio.run(main()) ``` -------------------------------- ### Get Possible Breakpoints (Python) Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/debugger Retrieves a list of possible locations where a breakpoint can be set within a specified range of a script. The search can be optionally restricted to the current function. Requires a start location and can optionally take an end location and a flag to restrict the search to the function scope. Returns a list of BreakLocation objects. ```python def get_possible_breakpoints( start: Location, end: typing.Optional[Location] = None, restrict_to_function: typing.Optional[bool] = None ) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, typing.List[BreakLocation]]: ''' Returns possible locations for breakpoint. :param start: Start of range to search possible breakpoint locations in. :param end: *(Optional)* End of range to search possible breakpoint locations in (excluding). When not specified, end of scripts is used as end of range. :param restrict_to_function: *(Optional)* Only consider locations which are in the same (non-nested) function as start. :returns: List of the possible breakpoint locations. ''' params: T_JSON_DICT = dict() params['start'] = start.to_json() if end is not None: params['end'] = end.to_json() if restrict_to_function is not None: params['restrictToFunction'] = restrict_to_function cmd_dict: T_JSON_DICT = { 'method': 'Debugger.getPossibleBreakpoints', 'params': params, } json = yield cmd_dict return [BreakLocation.from_json(i) for i in json['locations']] ``` -------------------------------- ### enable Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/cdp/dom_storage Enables storage tracking; storage events will now be delivered to the client. ```APIDOC ## enable ### Description Enables storage tracking; storage events will now be delivered to the client. ### Method POST ### Endpoint enable ### Parameters No parameters. ### Request Example {} ### Response #### Success Response (200) - No content returned. ``` -------------------------------- ### Install nodriver Package Source: https://ultrafunkamsterdam.github.io/nodriver/readme This command installs the nodriver Python package using pip. Ensure you have Python and pip installed on your system. ```shell pip install nodriver ``` -------------------------------- ### Start Worker Source: https://ultrafunkamsterdam.github.io/nodriver/nodriver/cdp/service_worker Starts a service worker at a given scope URL. ```APIDOC ## start_worker /websites/ultrafunkamsterdam_github_io_nodriver ### Description Starts a service worker for the specified scope URL. ### Method POST ### Endpoint /websites/ultrafunkamsterdam_github_io_nodriver/start_worker ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **scope_url** (str) - Required - The URL of the service worker scope. ### Request Example ```json { "scope_url": "/service-worker.js" } ``` ### Response #### Success Response (200) - **status** (str) - Indicates the status of the operation. #### Response Example ```json { "status": "worker_started" } ``` ``` -------------------------------- ### Page.getInstallabilityErrors Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/page Retrieves a list of installability errors for the current page. This is an EXPERIMENTAL feature. ```APIDOC ## GET /Page/getInstallabilityErrors ### Description Retrieves a list of installability errors for the current page. This is an EXPERIMENTAL feature. ### Method GET ### Endpoint /Page/getInstallabilityErrors ### Parameters None ### Request Example ```json { "method": "Page.getInstallabilityErrors" } ``` ### Response #### Success Response (200) - **installabilityErrors** (Array[InstallabilityError]) - A list of installability errors. #### Response Example ```json { "installabilityErrors": [ { "errorType": "ManifestUnobtainable", "errorId": "manifest-unobtainable", "errorMessage": "Manifest is unobtainable." } ] } ``` ``` -------------------------------- ### Storage - Get Interest Group Details Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/storage Gets details for a named interest group. EXPERIMENTAL. ```APIDOC ## GET /json/Storage.getInterestGroupDetails ### Description Gets details for a named interest group. EXPERIMENTAL. ### Method GET ### Endpoint /json/Storage.getInterestGroupDetails ### Parameters #### Query Parameters - **ownerOrigin** (string) - Required - The owner origin of the interest group. - **name** (string) - Required - The name of the interest group. ### Request Example ```json { "ownerOrigin": "https://buyer.com", "name": "exampleInterestGroup" } ``` ### Response #### Success Response (200) - **details** (object) - An object containing the interest group details. - **ownerOrigin** (string) - The owner origin. - **name** (string) - The name of the interest group. - **joiningOrigin** (string) - The origin from which the user joined the group. - **expirationTime** (number) - The absolute expiration time of the interest group. - (Other properties may be present as described in the specification) #### Response Example ```json { "details": { "ownerOrigin": "https://buyer.com", "name": "exampleInterestGroup", "joiningOrigin": "https://user.com", "expirationTime": 1678886400000 } } ``` ``` -------------------------------- ### Page.downloadWillBegin Source: https://ultrafunkamsterdam.github.io/nodriver/_modules/nodriver/cdp/page Fired when page is about to start a download. This event is deprecated and will be removed in a future version. Use Browser.downloadWillBegin instead. This is an EXPERIMENTAL event. ```APIDOC ## Page.downloadWillBegin ### Description Fired when page is about to start a download. EXPERIMENTAL. Deprecated. ### Method EVENT ### Endpoint Page.downloadWillBegin ### Parameters #### Event Parameters - **frameId** (FrameId) - Id of the frame that caused download to begin. - **guid** (string) - Global unique identifier of the download. - **url** (string) - URL of the resource being downloaded. - **suggestedFilename** (string) - Suggested file name of the resource. ### Response Example ```json { "method": "Page.downloadWillBegin", "params": { "frameId": "frameId_value", "guid": "download_guid", "url": "http://example.com/file.zip", "suggestedFilename": "file.zip" } } ``` ```