Skip to main content

Overview

nodriver provides utility functions in the nodriver.core.util module and exports commonly used ones at the top level. These functions help with event loops, browser management, DOM traversal, and more.

Event Loop Functions

loop()

Create a new asyncio event loop.
See the loop() API reference for details. Example:

Browser Management

start()

Launch a browser instance.
See the start() API reference for details.

get_registered_instances()

Get all active browser instances.
Returns: Set of all Browser instances that have been started. Example:

deconstruct_browser()

Clean up browser instances and temporary profiles.
Browser
default:"None"
Specific browser to clean up. If None, cleans up all registered instances.
Example:

free_port()

Find an available port for browser debugging.
Returns: Available port number. Example:

DOM Traversal

filter_recurse()

Find the first element matching a predicate by recursively traversing the DOM tree.
cdp.dom.Node | Element
required
Root node to start traversal from.
Callable
required
Function that takes a node and returns True to select it.
Returns: First node matching the predicate, or None. Example:

filter_recurse_all()

Find all elements matching a predicate by recursively traversing the DOM tree.
cdp.dom.Node | Element
required
Root node to start traversal from.
Callable
required
Function that takes a node and returns True to include it.
Returns: List of all nodes matching the predicate. Example:

Frame Tree Functions

flatten_frame_tree()

Flatten a hierarchical frame tree into a flat list of frames.
cdp.page.FrameResourceTree | cdp.page.FrameTree
required
Frame tree to flatten.
Yields: Frame objects from the tree. Example:

flatten_frame_tree_resources()

Flatten frame tree and yield frame-resource pairs.
Yields: Tuples of (frame, resource) for each resource in the tree.

Geometry Functions

circle()

Generate coordinates around a circle for smooth circular motion.
float
required
Center X coordinate.
float
default:"None"
Center Y coordinate. If None, uses x value.
int
default:"10"
Circle radius in pixels.
int
default:"10"
Number of points to generate (higher = smoother but slower).
int
default:"0"
Direction: 0 for clockwise, 1 for counter-clockwise.
Yields: (x, y) coordinate tuples around the circle. Example:

CDP Helper Functions

cdp_get_module()

Get a CDP module by domain name.
str | ModuleType
required
Domain name (e.g., ‘page’, ‘network’) or module object.
Returns: CDP domain module. Example:

Comparison Functions

compare_target_info()

Compare two TargetInfo objects and return differences.
Returns: List of tuples (field_name, old_value, new_value) for changed fields. Example:

Advanced Functions

create_from_undetected_chromedriver()

Create a nodriver Browser from an undetected_chromedriver instance.
undetected_chromedriver.Chrome
required
Running undetected_chromedriver instance.
Returns: nodriver Browser instance connected to the same browser. Example:

html_from_tree()

Extract HTML from a DOM tree.
cdp.dom.Node | Element
required
DOM tree or element.
Tab
required
Tab instance for sending CDP commands.
Returns: HTML string.

remove_from_tree()

Remove a node from a DOM tree.
Returns: Modified tree with node removed.

Examples

Clean up all browsers on exit

Find elements with custom logic

Circular window animation

See also