Overview
nodriver provides utility functions in thenodriver.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.Browser Management
start()
Launch a browser instance.get_registered_instances()
Get all active browser instances.deconstruct_browser()
Clean up browser instances and temporary profiles.Browser
default:"None"
Specific browser to clean up. If None, cleans up all registered instances.
free_port()
Find an available port for browser debugging.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.
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.
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.
flatten_frame_tree_resources()
Flatten frame tree and yield frame-resource pairs.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.
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.
Comparison Functions
compare_target_info()
Compare two TargetInfo objects and return differences.Advanced Functions
create_from_undetected_chromedriver()
Create a nodriver Browser from an undetected_chromedriver instance.undetected_chromedriver.Chrome
required
Running undetected_chromedriver instance.
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.
remove_from_tree()
Remove a node from a DOM tree.Examples
Clean up all browsers on exit
Find elements with custom logic
Circular window animation
See also
- start() - Launch a browser
- Browser class - Browser instance management
- Element class - DOM element interaction