LayerTree#

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 LayerId[source]#

Unique Layer identifier.

class SnapshotId[source]#

Unique snapshot identifier.

class ScrollRect(rect, type_)[source]#

Rectangle where scrolling happens on the main thread.

rect: Rect#

Rectangle itself.

type_: str#

Reason for rectangle to force scrolling on the main thread

class StickyPositionConstraint(sticky_box_rect, containing_block_rect, nearest_layer_shifting_sticky_box=None, nearest_layer_shifting_containing_block=None)[source]#

Sticky position constraints.

sticky_box_rect: Rect#

Layout rectangle of the sticky element before being shifted

containing_block_rect: Rect#

Layout rectangle of the containing block of the sticky element

nearest_layer_shifting_sticky_box: Optional[LayerId] = None#

The nearest sticky layer that shifts the sticky box

nearest_layer_shifting_containing_block: Optional[LayerId] = None#

The nearest sticky layer that shifts the containing block

class PictureTile(x, y, picture)[source]#

Serialized fragment of layer picture along with its offset within the layer.

x: float#

Offset from owning layer left boundary

y: float#

Offset from owning layer top boundary

picture: str#

Base64-encoded snapshot data. (Encoded as a base64 string when passed over JSON)

class Layer(layer_id, offset_x, offset_y, width, height, paint_count, draws_content, parent_layer_id=None, backend_node_id=None, transform=None, anchor_x=None, anchor_y=None, anchor_z=None, invisible=None, scroll_rects=None, sticky_position_constraint=None)[source]#

Information about a compositing layer.

layer_id: LayerId#

The unique id for this layer.

offset_x: float#

Offset from parent layer, X coordinate.

offset_y: float#

Offset from parent layer, Y coordinate.

width: float#

Layer width.

height: float#

Layer height.

paint_count: int#

Indicates how many time this layer has painted.

draws_content: bool#

Indicates whether this layer hosts any content, rather than being used for transform/scrolling purposes only.

parent_layer_id: Optional[LayerId] = None#

The id of parent (not present for root).

backend_node_id: Optional[BackendNodeId] = None#

The backend id for the node associated with this layer.

transform: Optional[List[float]] = None#

Transformation matrix for layer, default is identity matrix

anchor_x: Optional[float] = None#

Transform anchor point X, absent if no transform specified

anchor_y: Optional[float] = None#

Transform anchor point Y, absent if no transform specified

anchor_z: Optional[float] = None#

Transform anchor point Z, absent if no transform specified

invisible: Optional[bool] = None#

Set if layer is not visible.

scroll_rects: Optional[List[ScrollRect]] = None#

Rectangles scrolling on main thread only.

sticky_position_constraint: Optional[StickyPositionConstraint] = None#

Sticky position constraint information

class PaintProfile(iterable=(), /)[source]#

Array of timings, one per paint step.

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.

compositing_reasons(layer_id)[source]#

Provides the reasons why the given layer was composited.

Parameters:

layer_id (LayerId) – The id of the layer for which we want to get the reasons it was composited.

Return type:

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

Returns:

A tuple with the following items:

  1. compositingReasons - A list of strings specifying reasons for the given layer to become composited.

  2. compositingReasonIds - A list of strings specifying reason IDs for the given layer to become composited.

disable()[source]#

Disables compositing tree inspection.

Return type:

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

enable()[source]#

Enables compositing tree inspection.

Return type:

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

load_snapshot(tiles)[source]#

Returns the snapshot identifier.

Parameters:

tiles (List[PictureTile]) – An array of tiles composing the snapshot.

Return type:

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

Returns:

The id of the snapshot.

make_snapshot(layer_id)[source]#

Returns the layer snapshot identifier.

Parameters:

layer_id (LayerId) – The id of the layer.

Return type:

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

Returns:

The id of the layer snapshot.

profile_snapshot(snapshot_id, min_repeat_count=None, min_duration=None, clip_rect=None)[source]#
Parameters:
  • snapshot_id (SnapshotId) – The id of the layer snapshot.

  • min_repeat_count (Optional[int]) – (Optional) The maximum number of times to replay the snapshot (1, if not specified).

  • min_duration (Optional[float]) – (Optional) The minimum duration (in seconds) to replay the snapshot.

  • clip_rect (Optional[Rect]) – (Optional) The clip rectangle to apply when replaying the snapshot.

Return type:

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

Returns:

The array of paint profiles, one per run.

release_snapshot(snapshot_id)[source]#

Releases layer snapshot captured by the back-end.

Parameters:

snapshot_id (SnapshotId) – The id of the layer snapshot.

Return type:

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

replay_snapshot(snapshot_id, from_step=None, to_step=None, scale=None)[source]#

Replays the layer snapshot and returns the resulting bitmap.

Parameters:
  • snapshot_id (SnapshotId) – The id of the layer snapshot.

  • from_step (Optional[int]) – (Optional) The first step to replay from (replay from the very start if not specified).

  • to_step (Optional[int]) – (Optional) The last step to replay to (replay till the end if not specified).

  • scale (Optional[float]) – (Optional) The scale to apply while replaying (defaults to 1).

Return type:

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

Returns:

A data: URL for resulting image.

snapshot_command_log(snapshot_id)[source]#

Replays the layer snapshot and returns canvas log.

Parameters:

snapshot_id (SnapshotId) – The id of the layer snapshot.

Return type:

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

Returns:

The array of canvas function calls.

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 LayerPainted(layer_id, clip)[source]#
layer_id: LayerId#

The id of the painted layer.

clip: Rect#

Clip rectangle.

class LayerTreeDidChange(layers)[source]#
layers: Optional[List[Layer]]#

Layer tree, absent if not in the compositing mode.