Overlay

This domain provides various functionality related to drawing atop the inspected page.

This CDP domain is experimental.

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.overlay.HighlightConfig(show_info=None, show_styles=None, show_rulers=None, show_extension_lines=None, content_color=None, padding_color=None, border_color=None, margin_color=None, event_target_color=None, shape_color=None, shape_margin_color=None, css_grid_color=None)

Configuration data for the highlighting of page elements.

border_color = None

The border highlight fill color (default: transparent).

content_color = None

The content box highlight fill color (default: transparent).

css_grid_color = None

The grid layout color (default: transparent).

event_target_color = None

The event target element highlight fill color (default: transparent).

margin_color = None

The margin highlight fill color (default: transparent).

padding_color = None

The padding highlight fill color (default: transparent).

shape_color = None

The shape outside fill color (default: transparent).

shape_margin_color = None

The shape margin fill color (default: transparent).

show_extension_lines = None

Whether the extension lines from node to the rulers should be shown (default: false).

show_info = None

Whether the node info tooltip should be shown (default: false).

show_rulers = None

Whether the rulers should be shown (default: false).

show_styles = None

Whether the node styles in the tooltip (default: false).

class cdp.overlay.InspectMode

An enumeration.

CAPTURE_AREA_SCREENSHOT = 'captureAreaScreenshot'
NONE = 'none'
SEARCH_FOR_NODE = 'searchForNode'
SEARCH_FOR_UA_SHADOW_DOM = 'searchForUAShadowDOM'
SHOW_DISTANCES = 'showDistances'

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.overlay.disable()

Disables domain notifications.

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

Enables domain notifications.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.overlay.get_highlight_object_for_test(node_id, include_distance=None, include_style=None)

For testing.

Parameters:
  • node_id (NodeId) – Id of the node to get highlight object for.
  • include_distance (Optional[bool]) – (Optional) Whether to include distance info.
  • include_style (Optional[bool]) – (Optional) Whether to include style info.
Return type:

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

Returns:

Highlight data for the node.

cdp.overlay.hide_highlight()

Hides any highlight.

Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.overlay.highlight_frame(frame_id, content_color=None, content_outline_color=None)

Highlights owner element of the frame with given id.

Parameters:
  • frame_id (FrameId) – Identifier of the frame to highlight.
  • content_color (Optional[RGBA]) – (Optional) The content box highlight fill color (default: transparent).
  • content_outline_color (Optional[RGBA]) – (Optional) The content box highlight outline color (default: transparent).
Return type:

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

cdp.overlay.highlight_node(highlight_config, node_id=None, backend_node_id=None, object_id=None, selector=None)

Highlights DOM node with given id or with the given JavaScript object wrapper. Either nodeId or objectId must be specified.

Parameters:
  • highlight_config (HighlightConfig) – A descriptor for the highlight appearance.
  • node_id (Optional[NodeId]) – (Optional) Identifier of the node to highlight.
  • backend_node_id (Optional[BackendNodeId]) – (Optional) Identifier of the backend node to highlight.
  • object_id (Optional[RemoteObjectId]) – (Optional) JavaScript object id of the node to be highlighted.
  • selector (Optional[str]) – (Optional) Selectors to highlight relevant nodes.
Return type:

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

cdp.overlay.highlight_quad(quad, color=None, outline_color=None)

Highlights given quad. Coordinates are absolute with respect to the main frame viewport.

Parameters:
  • quad (Quad) – Quad to highlight
  • color (Optional[RGBA]) – (Optional) The highlight fill color (default: transparent).
  • outline_color (Optional[RGBA]) – (Optional) The highlight outline color (default: transparent).
Return type:

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

cdp.overlay.highlight_rect(x, y, width, height, color=None, outline_color=None)

Highlights given rectangle. Coordinates are absolute with respect to the main frame viewport.

Parameters:
  • x (int) – X coordinate
  • y (int) – Y coordinate
  • width (int) – Rectangle width
  • height (int) – Rectangle height
  • color (Optional[RGBA]) – (Optional) The highlight fill color (default: transparent).
  • outline_color (Optional[RGBA]) – (Optional) The highlight outline color (default: transparent).
Return type:

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

cdp.overlay.set_inspect_mode(mode, highlight_config=None)

Enters the ‘inspect’ mode. In this mode, elements that user is hovering over are highlighted. Backend then generates ‘inspectNodeRequested’ event upon element selection.

Parameters:
  • mode (InspectMode) – Set an inspection mode.
  • highlight_config (Optional[HighlightConfig]) – (Optional) A descriptor for the highlight appearance of hovered-over nodes. May be omitted if `enabled == false`.
Return type:

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

cdp.overlay.set_paused_in_debugger_message(message=None)
Parameters:message (Optional[str]) – (Optional) The message to display, also triggers resume and step over controls.
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.overlay.set_show_ad_highlights(show)

Highlights owner element of all frames detected to be ads.

Parameters:show (bool) – True for showing ad highlights
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.overlay.set_show_debug_borders(show)

Requests that backend shows debug borders on layers

Parameters:show (bool) – True for showing debug borders
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.overlay.set_show_fps_counter(show)

Requests that backend shows the FPS counter

Parameters:show (bool) – True for showing the FPS counter
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.overlay.set_show_hit_test_borders(show)

Requests that backend shows hit-test borders on layers

Parameters:show (bool) – True for showing hit-test borders
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.overlay.set_show_layout_shift_regions(result)

Requests that backend shows layout shift regions

Parameters:result (bool) – True for showing layout shift regions
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.overlay.set_show_paint_rects(result)

Requests that backend shows paint rectangles

Parameters:result (bool) – True for showing paint rectangles
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.overlay.set_show_scroll_bottleneck_rects(show)

Requests that backend shows scroll bottleneck rects

Parameters:show (bool) – True for showing scroll bottleneck rects
Return type:Generator[Dict[str, Any], Dict[str, Any], None]
cdp.overlay.set_show_viewport_size_on_resize(show)

Paints viewport size upon main frame resize.

Parameters:show (bool) – Whether to paint size or not.
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.overlay.InspectNodeRequested(backend_node_id)

Fired when the node should be inspected. This happens after call to setInspectMode or when user manually inspects an element.

backend_node_id = None

Id of the node to inspect.

class cdp.overlay.NodeHighlightRequested(node_id)

Fired when the node should be highlighted. This happens after call to setInspectMode.

class cdp.overlay.ScreenshotRequested(viewport)

Fired when user asks to capture screenshot of some area on the page.

viewport = None

Viewport to capture, in device independent pixels (dip).

class cdp.overlay.InspectModeCanceled

Fired when user cancels the inspect mode.