Page

Actions and events related to the inspected page belong to the page domain.

Types

Generally, you do not need to instantiate CDP types yourself. Instead, the API creates objects for you as return values from commands, and then you can use those objects as arguments to other commands.

class cdp.page.FrameId

Unique frame identifier.

class cdp.page.Frame(id_, loader_id, url, security_origin, mime_type, parent_id=None, name=None, url_fragment=None, unreachable_url=None)

Information about the Frame on the page.

id_ = None

Frame unique identifier.

loader_id = None

Identifier of the loader associated with this frame.

mime_type = None

Frame document’s mimeType as determined by the browser.

name = None

Frame’s name as specified in the tag.

parent_id = None

Parent frame identifier.

security_origin = None

Frame document’s security origin.

unreachable_url = None

If the frame failed to load, this contains the URL that could not be loaded. Note that unlike url above, this URL may contain a fragment.

url = None

Frame document’s URL without fragment.

url_fragment = None

Frame document’s URL fragment including the ‘#’.

class cdp.page.FrameResource(url, type_, mime_type, last_modified=None, content_size=None, failed=None, canceled=None)

Information about the Resource on the page.

canceled = None

True if the resource was canceled during loading.

content_size = None

Resource content size.

failed = None

True if the resource failed to load.

last_modified = None

last-modified timestamp as reported by server.

mime_type = None

Resource mimeType as determined by the browser.

type_ = None

Type of this resource.

url = None

Resource URL.

class cdp.page.FrameResourceTree(frame, resources, child_frames=None)

Information about the Frame hierarchy along with their cached resources.

child_frames = None

Child frames.

frame = None

Frame information for this tree item.

resources = None

Information about frame resources.

class cdp.page.FrameTree(frame, child_frames=None)

Information about the Frame hierarchy.

child_frames = None

Child frames.

frame = None

Frame information for this tree item.

class cdp.page.ScriptIdentifier

Unique script identifier.

class cdp.page.TransitionType

Transition type.

ADDRESS_BAR = 'address_bar'
AUTO_BOOKMARK = 'auto_bookmark'
AUTO_SUBFRAME = 'auto_subframe'
AUTO_TOPLEVEL = 'auto_toplevel'
FORM_SUBMIT = 'form_submit'
GENERATED = 'generated'
KEYWORD = 'keyword'
KEYWORD_GENERATED = 'keyword_generated'
MANUAL_SUBFRAME = 'manual_subframe'
OTHER = 'other'
RELOAD = 'reload'
TYPED = 'typed'
class cdp.page.NavigationEntry(id_, url, user_typed_url, title, transition_type)

Navigation history entry.

id_ = None

Unique id of the navigation history entry.

title = None

Title of the navigation history entry.

transition_type = None

Transition type.

url = None

URL of the navigation history entry.

user_typed_url = None

URL that the user typed in the url bar.

class cdp.page.ScreencastFrameMetadata(offset_top, page_scale_factor, device_width, device_height, scroll_offset_x, scroll_offset_y, timestamp=None)

Screencast frame metadata.

device_height = None

Device screen height in DIP.

device_width = None

Device screen width in DIP.

offset_top = None

Top offset in DIP.

page_scale_factor = None

Page scale factor.

scroll_offset_x = None

Position of horizontal scroll in CSS pixels.

scroll_offset_y = None

Position of vertical scroll in CSS pixels.

timestamp = None

Frame swap timestamp.

class cdp.page.DialogType

Javascript dialog type.

ALERT = 'alert'
BEFOREUNLOAD = 'beforeunload'
CONFIRM = 'confirm'
PROMPT = 'prompt'
class cdp.page.AppManifestError(message, critical, line, column)

Error while paring app manifest.

column = None

Error column.

critical = None

If criticial, this is a non-recoverable parse error.

line = None

Error line.

message = None

Error message.

class cdp.page.LayoutViewport(page_x, page_y, client_width, client_height)

Layout viewport position and dimensions.

client_height = None

Height (CSS pixels), excludes scrollbar if present.

client_width = None

Width (CSS pixels), excludes scrollbar if present.

page_x = None

Horizontal offset relative to the document (CSS pixels).

page_y = None

Vertical offset relative to the document (CSS pixels).

class cdp.page.VisualViewport(offset_x, offset_y, page_x, page_y, client_width, client_height, scale, zoom=None)

Visual viewport position, dimensions, and scale.

client_height = None

Height (CSS pixels), excludes scrollbar if present.

client_width = None

Width (CSS pixels), excludes scrollbar if present.

offset_x = None

Horizontal offset relative to the layout viewport (CSS pixels).

offset_y = None

Vertical offset relative to the layout viewport (CSS pixels).

page_x = None

Horizontal offset relative to the document (CSS pixels).

page_y = None

Vertical offset relative to the document (CSS pixels).

scale = None

Scale relative to the ideal viewport (size at width=device-width).

zoom = None

Page zoom factor (CSS to device independent pixels ratio).

class cdp.page.Viewport(x, y, width, height, scale)

Viewport for capturing screenshot.

height = None

Rectangle height in device independent pixels (dip).

scale = None

Page scale factor.

width = None

Rectangle width in device independent pixels (dip).

x = None

X offset in device independent pixels (dip).

y = None

Y offset in device independent pixels (dip).

class cdp.page.FontFamilies(standard=None, fixed=None, serif=None, sans_serif=None, cursive=None, fantasy=None, pictograph=None)

Generic font families collection.

cursive = None

The cursive font-family.

fantasy = None

The fantasy font-family.

fixed = None

The fixed font-family.

pictograph = None

The pictograph font-family.

sans_serif = None

The sansSerif font-family.

serif = None

The serif font-family.

standard = None

The standard font-family.

class cdp.page.FontSizes(standard=None, fixed=None)

Default font sizes.

fixed = None

Default fixed font size.

standard = None

Default standard font size.

class cdp.page.ClientNavigationReason

An enumeration.

FORM_SUBMISSION_GET = 'formSubmissionGet'
FORM_SUBMISSION_POST = 'formSubmissionPost'
HTTP_HEADER_REFRESH = 'httpHeaderRefresh'
META_TAG_REFRESH = 'metaTagRefresh'
PAGE_BLOCK_INTERSTITIAL = 'pageBlockInterstitial'
RELOAD = 'reload'
SCRIPT_INITIATED = 'scriptInitiated'

Commands

Each command is a generator function. The return type Generator[x, y, z] indicates that the generator yields arguments of type x, it must be resumed with an argument of type y, and it returns type z. In this library, types x and y are the same for all commands, and z is the return type you should pay attention to. For more information, see Getting Started: Commands.

cdp.page.add_compilation_cache(url, data)

Seeds compilation cache for given url. Compilation cache does not survive cross-process navigation.

EXPERIMENTAL

Parameters:
  • url (str) –
  • data (str) – Base64-encoded data
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.page.add_script_to_evaluate_on_load(script_source)

Deprecated, please use addScriptToEvaluateOnNewDocument instead.

Deprecated since version 1.3.

EXPERIMENTAL

Parameters:script_source (str) –
Return type:Generator[Dict[str, Any], Dict[str, Any], ScriptIdentifier]
Returns:Identifier of the added script.

Deprecated since version 1.3.

cdp.page.add_script_to_evaluate_on_new_document(source, world_name=None)

Evaluates given script in every frame upon creation (before loading frame’s scripts).

Parameters:
  • source (str) –
  • world_name (Optional[str]) – (EXPERIMENTAL) (Optional) If specified, creates an isolated world with the given name and evaluates given script in it. This world name will be used as the ExecutionContextDescription::name when the corresponding event is emitted.
Return type:

Generator[Dict[str, Any], Dict[str, Any], ScriptIdentifier]

Returns:

Identifier of the added script.

cdp.page.bring_to_front()

Brings page to front (activates tab).

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.capture_screenshot(format_=None, quality=None, clip=None, from_surface=None)

Capture page screenshot.

Parameters:
  • format(Optional) Image compression format (defaults to png).
  • quality (Optional[int]) – (Optional) Compression quality from range [0..100] (jpeg only).
  • clip (Optional[Viewport]) – (Optional) Capture the screenshot of a given region only.
  • from_surface (Optional[bool]) – (EXPERIMENTAL) (Optional) Capture the screenshot from the surface, rather than the view. Defaults to true.
Return type:

Generator[Dict[str, Any], Dict[str, Any], str]

Returns:

Base64-encoded image data.

cdp.page.capture_snapshot(format_=None)

Returns a snapshot of the page as a string. For MHTML format, the serialization includes iframes, shadow DOM, external resources, and element-inline styles.

EXPERIMENTAL

Parameters:format(Optional) Format (defaults to mhtml).
Return type:Generator[Dict[str, Any], Dict[str, Any], str]
Returns:Serialized page data.
cdp.page.clear_compilation_cache()

Clears seeded compilation cache.

EXPERIMENTAL

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.clear_device_metrics_override()

Clears the overriden device metrics.

Deprecated since version 1.3.

EXPERIMENTAL

Deprecated since version 1.3.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.clear_device_orientation_override()

Clears the overridden Device Orientation.

Deprecated since version 1.3.

EXPERIMENTAL

Deprecated since version 1.3.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.clear_geolocation_override()

Clears the overriden Geolocation Position and Error.

Deprecated since version 1.3.

Deprecated since version 1.3.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.close()

Tries to close page, running its beforeunload hooks, if any.

EXPERIMENTAL

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.crash()

Crashes renderer on the IO thread, generates minidumps.

EXPERIMENTAL

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.create_isolated_world(frame_id, world_name=None, grant_univeral_access=None)

Creates an isolated world for the given frame.

Parameters:
  • frame_id (FrameId) – Id of the frame in which the isolated world should be created.
  • world_name (Optional[str]) – (Optional) An optional name which is reported in the Execution Context.
  • grant_univeral_access (Optional[bool]) – (Optional) Whether or not universal access should be granted to the isolated world. This is a powerful option, use with caution.
Return type:

Generator[Dict[str, Any], Dict[str, Any], ExecutionContextId]

Returns:

Execution context of the isolated world.

Deletes browser cookie with given name, domain and path.

Deprecated since version 1.3.

EXPERIMENTAL

Parameters:
  • cookie_name (str) – Name of the cookie to remove.
  • url (str) – URL to match cooke domain and path.

Deprecated since version 1.3.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.disable()

Disables page domain notifications.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.enable()

Enables page domain notifications.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.generate_test_report(message, group=None)

Generates a report for testing.

EXPERIMENTAL

Parameters:
  • message (str) – Message to be displayed in the report.
  • group (Optional[str]) – (Optional) Specifies the endpoint group to deliver the report to.
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.page.get_app_manifest()
Return type:Generator[Dict[str, Any], Dict[str, Any], Tuple[str, List[AppManifestError], Optional[str]]]
Returns:A tuple with the following items:
  1. url - Manifest location.
  2. errors -
  3. data - (Optional) Manifest content.
cdp.page.get_cookies()

Returns all browser cookies. Depending on the backend support, will return detailed cookie information in the cookies field.

Deprecated since version 1.3.

EXPERIMENTAL

Return type:Generator[Dict[str, Any], Dict[str, Any], List[Cookie]]
Returns:Array of cookie objects.

Deprecated since version 1.3.

cdp.page.get_frame_tree()

Returns present frame tree structure.

Return type:Generator[Dict[str, Any], Dict[str, Any], FrameTree]
Returns:Present frame tree structure.
cdp.page.get_installability_errors()

EXPERIMENTAL

Return type:Generator[Dict[str, Any], Dict[str, Any], List[str]]
Returns:
cdp.page.get_layout_metrics()

Returns metrics relating to the layouting of the page, such as viewport bounds/scale.

Return type:Generator[Dict[str, Any], Dict[str, Any], Tuple[LayoutViewport, VisualViewport, Rect]]
Returns:A tuple with the following items:
  1. layoutViewport - Metrics relating to the layout viewport.
  2. visualViewport - Metrics relating to the visual viewport.
  3. contentSize - Size of scrollable area.
cdp.page.get_navigation_history()

Returns navigation history for the current page.

Return type:Generator[Dict[str, Any], Dict[str, Any], Tuple[int, List[NavigationEntry]]]
Returns:A tuple with the following items:
  1. currentIndex - Index of the current navigation history entry.
  2. entries - Array of navigation history entries.
cdp.page.get_resource_content(frame_id, url)

Returns content of the given resource.

EXPERIMENTAL

Parameters:
  • frame_id (FrameId) – Frame id to get resource for.
  • url (str) – URL of the resource to get content for.
Return type:

Generator[Dict[str, Any], Dict[str, Any], Tuple[str, bool]]

Returns:

A tuple with the following items:

  1. content - Resource content.
  2. base64Encoded - True, if content was served as base64.

cdp.page.get_resource_tree()

Returns present frame / resource tree structure.

EXPERIMENTAL

Return type:Generator[Dict[str, Any], Dict[str, Any], FrameResourceTree]
Returns:Present frame / resource tree structure.
cdp.page.handle_file_chooser(action, files=None)

Accepts or cancels an intercepted file chooser dialog.

EXPERIMENTAL

Parameters:
  • action (str) –
  • files (Optional[List[str]]) – (Optional) Array of absolute file paths to set, only respected with `accept` action.
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.page.handle_java_script_dialog(accept, prompt_text=None)

Accepts or dismisses a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload).

Parameters:
  • accept (bool) – Whether to accept or dismiss the dialog.
  • prompt_text (Optional[str]) – (Optional) The text to enter into the dialog prompt before accepting. Used only if this is a prompt dialog.
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.page.navigate(url, referrer=None, transition_type=None, frame_id=None)

Navigates current page to the given URL.

Parameters:
  • url (str) – URL to navigate the page to.
  • referrer (Optional[str]) – (Optional) Referrer URL.
  • transition_type (Optional[TransitionType]) – (Optional) Intended transition type.
  • frame_id (Optional[FrameId]) – (Optional) Frame id to navigate, if not specified navigates the top frame.
Return type:

Generator[Dict[str, Any], Dict[str, Any], Tuple[FrameId, Optional[LoaderId], Optional[str]]]

Returns:

A tuple with the following items:

  1. frameId - Frame id that has navigated (or failed to navigate)
  2. loaderId - (Optional) Loader identifier.
  3. errorText - (Optional) User friendly error message, present if and only if navigation has failed.

cdp.page.navigate_to_history_entry(entry_id)

Navigates current page to the given history entry.

Parameters:entry_id (int) – Unique id of the entry to navigate to.
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.print_to_pdf(landscape=None, display_header_footer=None, print_background=None, scale=None, paper_width=None, paper_height=None, margin_top=None, margin_bottom=None, margin_left=None, margin_right=None, page_ranges=None, ignore_invalid_page_ranges=None, header_template=None, footer_template=None, prefer_css_page_size=None, transfer_mode=None)

Print page as PDF.

Parameters:
  • landscape (Optional[bool]) – (Optional) Paper orientation. Defaults to false.
  • display_header_footer (Optional[bool]) – (Optional) Display header and footer. Defaults to false.
  • print_background (Optional[bool]) – (Optional) Print background graphics. Defaults to false.
  • scale (Optional[float]) – (Optional) Scale of the webpage rendering. Defaults to 1.
  • paper_width (Optional[float]) – (Optional) Paper width in inches. Defaults to 8.5 inches.
  • paper_height (Optional[float]) – (Optional) Paper height in inches. Defaults to 11 inches.
  • margin_top (Optional[float]) – (Optional) Top margin in inches. Defaults to 1cm (~0.4 inches).
  • margin_bottom (Optional[float]) – (Optional) Bottom margin in inches. Defaults to 1cm (~0.4 inches).
  • margin_left (Optional[float]) – (Optional) Left margin in inches. Defaults to 1cm (~0.4 inches).
  • margin_right (Optional[float]) – (Optional) Right margin in inches. Defaults to 1cm (~0.4 inches).
  • page_ranges (Optional[str]) – (Optional) Paper ranges to print, e.g., ‘1-5, 8, 11-13’. Defaults to the empty string, which means print all pages.
  • ignore_invalid_page_ranges (Optional[bool]) – (Optional) Whether to silently ignore invalid but successfully parsed page ranges, such as ‘3-2’. Defaults to false.
  • header_template (Optional[str]) – (Optional) HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them: - `date``: formatted print date - ``title``: document title - ``url``: document location - ``pageNumber``: current page number - ``totalPages``: total pages in the document For example, ``<span class=title></span>`` would generate span containing the title.
  • footer_template (Optional[str]) – (Optional) HTML template for the print footer. Should use the same format as the ``headerTemplate``.
  • prefer_css_page_size (Optional[bool]) – (Optional) Whether or not to prefer page size as defined by css. Defaults to false, in which case the content will be scaled to fit the paper size.
  • transfer_mode (Optional[str]) – (EXPERIMENTAL) (Optional) return as stream
Return type:

Generator[Dict[str, Any], Dict[str, Any], Tuple[str, Optional[StreamHandle]]]

Returns:

A tuple with the following items:

  1. data - Base64-encoded pdf data. Empty if `` returnAsStream` is specified.
  2. stream - (Optional) A handle of the stream that holds resulting PDF data.

cdp.page.reload(ignore_cache=None, script_to_evaluate_on_load=None)

Reloads given page optionally ignoring the cache.

Parameters:
  • ignore_cache (Optional[bool]) – (Optional) If true, browser cache is ignored (as if the user pressed Shift+refresh).
  • script_to_evaluate_on_load (Optional[str]) – (Optional) If set, the script will be injected into all frames of the inspected page after reload. Argument will be ignored if reloading dataURL origin.
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.page.remove_script_to_evaluate_on_load(identifier)

Deprecated, please use removeScriptToEvaluateOnNewDocument instead.

Deprecated since version 1.3.

EXPERIMENTAL

Parameters:identifier (ScriptIdentifier) –

Deprecated since version 1.3.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.remove_script_to_evaluate_on_new_document(identifier)

Removes given script from the list.

Parameters:identifier (ScriptIdentifier) –
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.reset_navigation_history()

Resets navigation history for the current page.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.screencast_frame_ack(session_id)

Acknowledges that a screencast frame has been received by the frontend.

EXPERIMENTAL

Parameters:session_id (int) – Frame number.
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.search_in_resource(frame_id, url, query, case_sensitive=None, is_regex=None)

Searches for given string in resource content.

EXPERIMENTAL

Parameters:
  • frame_id (FrameId) – Frame id for resource to search in.
  • url (str) – URL of the resource to search in.
  • query (str) – String to search for.
  • case_sensitive (Optional[bool]) – (Optional) If true, search is case sensitive.
  • is_regex (Optional[bool]) – (Optional) If true, treats string parameter as regex.
Return type:

Generator[Dict[str, Any], Dict[str, Any], List[SearchMatch]]

Returns:

List of search matches.

cdp.page.set_ad_blocking_enabled(enabled)

Enable Chrome’s experimental ad filter on all sites.

EXPERIMENTAL

Parameters:enabled (bool) – Whether to block ads.
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.set_bypass_csp(enabled)

Enable page Content Security Policy by-passing.

EXPERIMENTAL

Parameters:enabled (bool) – Whether to bypass page CSP.
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.set_device_metrics_override(width, height, device_scale_factor, mobile, scale=None, screen_width=None, screen_height=None, position_x=None, position_y=None, dont_set_visible_size=None, screen_orientation=None, viewport=None)

Overrides the values of device screen dimensions (window.screen.width, window.screen.height, window.innerWidth, window.innerHeight, and “device-width”/”device-height”-related CSS media query results).

Deprecated since version 1.3.

EXPERIMENTAL

Parameters:
  • width (int) – Overriding width value in pixels (minimum 0, maximum 10000000). 0 disables the override.
  • height (int) – Overriding height value in pixels (minimum 0, maximum 10000000). 0 disables the override.
  • device_scale_factor (float) – Overriding device scale factor value. 0 disables the override.
  • mobile (bool) – Whether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text autosizing and more.
  • scale (Optional[float]) – (Optional) Scale to apply to resulting view image.
  • screen_width (Optional[int]) – (Optional) Overriding screen width value in pixels (minimum 0, maximum 10000000).
  • screen_height (Optional[int]) – (Optional) Overriding screen height value in pixels (minimum 0, maximum 10000000).
  • position_x (Optional[int]) – (Optional) Overriding view X position on screen in pixels (minimum 0, maximum 10000000).
  • position_y (Optional[int]) – (Optional) Overriding view Y position on screen in pixels (minimum 0, maximum 10000000).
  • dont_set_visible_size (Optional[bool]) – (Optional) Do not set visible view size, rely upon explicit setVisibleSize call.
  • screen_orientation (Optional[ScreenOrientation]) – (Optional) Screen orientation override.
  • viewport (Optional[Viewport]) – (Optional) The viewport dimensions and scale. If not set, the override is cleared.

Deprecated since version 1.3.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.set_device_orientation_override(alpha, beta, gamma)

Overrides the Device Orientation.

Deprecated since version 1.3.

EXPERIMENTAL

Parameters:
  • alpha (float) – Mock alpha
  • beta (float) – Mock beta
  • gamma (float) – Mock gamma

Deprecated since version 1.3.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.set_document_content(frame_id, html)

Sets given markup as the document’s HTML.

Parameters:
  • frame_id (FrameId) – Frame id to set HTML for.
  • html (str) – HTML content to set.
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.page.set_download_behavior(behavior, download_path=None)

Set the behavior when downloading a file.

EXPERIMENTAL

Parameters:
  • behavior (str) – Whether to allow all or deny all download requests, or use default Chrome behavior if available (otherwise deny).
  • download_path (Optional[str]) – (Optional) The default path to save downloaded files to. This is requred if behavior is set to ‘allow’
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.page.set_font_families(font_families)

Set generic font families.

EXPERIMENTAL

Parameters:font_families (FontFamilies) – Specifies font families to set. If a font family is not specified, it won’t be changed.
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.set_font_sizes(font_sizes)

Set default font sizes.

EXPERIMENTAL

Parameters:font_sizes (FontSizes) – Specifies font sizes to set. If a font size is not specified, it won’t be changed.
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.set_geolocation_override(latitude=None, longitude=None, accuracy=None)

Overrides the Geolocation Position or Error. Omitting any of the parameters emulates position unavailable.

Deprecated since version 1.3.

Parameters:
  • latitude (Optional[float]) – (Optional) Mock latitude
  • longitude (Optional[float]) – (Optional) Mock longitude
  • accuracy (Optional[float]) – (Optional) Mock accuracy

Deprecated since version 1.3.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.set_intercept_file_chooser_dialog(enabled)

Intercept file chooser requests and transfer control to protocol clients. When file chooser interception is enabled, native file chooser dialog is not shown. Instead, a protocol event Page.fileChooserOpened is emitted. File chooser can be handled with page.handleFileChooser command.

EXPERIMENTAL

Parameters:enabled (bool) –
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.set_lifecycle_events_enabled(enabled)

Controls whether page will emit lifecycle events.

EXPERIMENTAL

Parameters:enabled (bool) – If true, starts emitting lifecycle events.
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.set_produce_compilation_cache(enabled)

Forces compilation cache to be generated for every subresource script.

EXPERIMENTAL

Parameters:enabled (bool) –
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.set_touch_emulation_enabled(enabled, configuration=None)

Toggles mouse event-based touch event emulation.

Deprecated since version 1.3.

EXPERIMENTAL

Parameters:
  • enabled (bool) – Whether the touch event emulation should be enabled.
  • configuration (Optional[str]) – (Optional) Touch/gesture events configuration. Default: current platform.

Deprecated since version 1.3.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.set_web_lifecycle_state(state)

Tries to update the web lifecycle state of the page. It will transition the page to the given state according to: https://github.com/WICG/web-lifecycle/

EXPERIMENTAL

Parameters:state (str) – Target lifecycle state
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.start_screencast(format_=None, quality=None, max_width=None, max_height=None, every_nth_frame=None)

Starts sending each frame using the screencastFrame event.

EXPERIMENTAL

Parameters:
  • format(Optional) Image compression format.
  • quality (Optional[int]) – (Optional) Compression quality from range [0..100].
  • max_width (Optional[int]) – (Optional) Maximum screenshot width.
  • max_height (Optional[int]) – (Optional) Maximum screenshot height.
  • every_nth_frame (Optional[int]) – (Optional) Send every n-th frame.
Return type:

Generator[Dict[str, Any], Dict[str, Any], None]

cdp.page.stop_loading()

Force the page stop all navigations and pending resource fetches.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.stop_screencast()

Stops sending each frame in the screencastFrame.

EXPERIMENTAL

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.page.wait_for_debugger()

Pauses page execution. Can be resumed using generic Runtime.runIfWaitingForDebugger.

EXPERIMENTAL

Return type:Generator[Dict[str, Any], Dict[str, Any], None]

Events

Generally, you do not need to instantiate CDP events yourself. Instead, the API creates events for you and then you use the event’s attributes.

class cdp.page.DomContentEventFired(timestamp)
class cdp.page.FileChooserOpened(mode)

Emitted only when page.interceptFileChooser is enabled.

class cdp.page.FrameAttached(frame_id, parent_frame_id, stack)

Fired when frame has been attached to its parent.

frame_id = None

Id of the frame that has been attached.

parent_frame_id = None

Parent frame identifier.

stack = None

JavaScript stack trace of when frame was attached, only set if frame initiated from script.

class cdp.page.FrameClearedScheduledNavigation(frame_id)

Fired when frame no longer has a scheduled navigation.

Deprecated since version 1.3.

frame_id = None

Id of the frame that has cleared its scheduled navigation.

class cdp.page.FrameDetached(frame_id)

Fired when frame has been detached from its parent.

frame_id = None

Id of the frame that has been detached.

class cdp.page.FrameNavigated(frame)

Fired once navigation of the frame has completed. Frame is now associated with the new loader.

frame = None

Frame object.

class cdp.page.FrameResized

EXPERIMENTAL

class cdp.page.FrameRequestedNavigation(frame_id, reason, url)

EXPERIMENTAL

Fired when a renderer-initiated navigation is requested. Navigation may still be cancelled after the event is issued.

frame_id = None

Id of the frame that is being navigated.

reason = None

The reason for the navigation.

url = None

The destination URL for the requested navigation.

class cdp.page.FrameScheduledNavigation(frame_id, delay, reason, url)

Fired when frame schedules a potential navigation.

Deprecated since version 1.3.

delay = None

Delay (in seconds) until the navigation is scheduled to begin. The navigation is not guaranteed to start.

frame_id = None

Id of the frame that has scheduled a navigation.

reason = None

The reason for the navigation.

url = None

The destination URL for the scheduled navigation.

class cdp.page.FrameStartedLoading(frame_id)

EXPERIMENTAL

Fired when frame has started loading.

frame_id = None

Id of the frame that has started loading.

class cdp.page.FrameStoppedLoading(frame_id)

EXPERIMENTAL

Fired when frame has stopped loading.

frame_id = None

Id of the frame that has stopped loading.

class cdp.page.DownloadWillBegin(frame_id, url)

EXPERIMENTAL

Fired when page is about to start a download.

frame_id = None

Id of the frame that caused download to begin.

url = None

URL of the resource being downloaded.

class cdp.page.InterstitialHidden

Fired when interstitial page was hidden

class cdp.page.InterstitialShown

Fired when interstitial page was shown

class cdp.page.JavascriptDialogClosed(result, user_input)

Fired when a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload) has been closed.

result = None

Whether dialog was confirmed.

user_input = None

User input in case of prompt.

class cdp.page.JavascriptDialogOpening(url, message, type_, has_browser_handler, default_prompt)

Fired when a JavaScript initiated dialog (alert, confirm, prompt, or onbeforeunload) is about to open.

default_prompt = None

Default dialog prompt.

has_browser_handler = None

True iff browser is capable showing or acting on the given dialog. When browser has no dialog handler for given target, calling alert while Page domain is engaged will stall the page execution. Execution can be resumed via calling Page.handleJavaScriptDialog.

message = None

Message that will be displayed by the dialog.

type_ = None

Dialog type.

url = None

Frame url.

class cdp.page.LifecycleEvent(frame_id, loader_id, name, timestamp)

Fired for top level page lifecycle events such as navigation, load, paint, etc.

frame_id = None

Id of the frame.

loader_id = None

Loader identifier. Empty string if the request is fetched from worker.

class cdp.page.LoadEventFired(timestamp)
class cdp.page.NavigatedWithinDocument(frame_id, url)

EXPERIMENTAL

Fired when same-document navigation happens, e.g. due to history API usage or anchor navigation.

frame_id = None

Id of the frame.

url = None

Frame’s new url.

class cdp.page.ScreencastFrame(data, metadata, session_id)

EXPERIMENTAL

Compressed image data requested by the startScreencast.

data = None

Base64-encoded compressed image.

metadata = None

Screencast frame metadata.

session_id = None

Frame number.

class cdp.page.ScreencastVisibilityChanged(visible)

EXPERIMENTAL

Fired when the page with currently enabled screencast was shown or hidden .

visible = None

True if the page is visible.

class cdp.page.WindowOpen(url, window_name, window_features, user_gesture)

Fired when a new window is going to be opened, via window.open(), link click, form submission, etc.

url = None

The URL for the new window.

user_gesture = None

Whether or not it was triggered by user gesture.

window_features = None

An array of enabled window features.

window_name = None

Window name.

class cdp.page.CompilationCacheProduced(url, data)

EXPERIMENTAL

Issued for every compilation cache generated. Is only available if Page.setGenerateCompilationCache is enabled.

data = None

Base64-encoded data