Skip to content

layer_tree

Layer dataclass

Information about a compositing layer.

Source code in zendriver/cdp/layer_tree.py
@dataclass
class Layer:
    """
    Information about a compositing layer.
    """

    #: The unique id for this layer.
    layer_id: LayerId

    #: Offset from parent layer, X coordinate.
    offset_x: float

    #: Offset from parent layer, Y coordinate.
    offset_y: float

    #: Layer width.
    width: float

    #: Layer height.
    height: float

    #: Indicates how many time this layer has painted.
    paint_count: int

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

    #: The id of parent (not present for root).
    parent_layer_id: typing.Optional[LayerId] = None

    #: The backend id for the node associated with this layer.
    backend_node_id: typing.Optional[dom.BackendNodeId] = None

    #: Transformation matrix for layer, default is identity matrix
    transform: typing.Optional[typing.List[float]] = None

    #: Transform anchor point X, absent if no transform specified
    anchor_x: typing.Optional[float] = None

    #: Transform anchor point Y, absent if no transform specified
    anchor_y: typing.Optional[float] = None

    #: Transform anchor point Z, absent if no transform specified
    anchor_z: typing.Optional[float] = None

    #: Set if layer is not visible.
    invisible: typing.Optional[bool] = None

    #: Rectangles scrolling on main thread only.
    scroll_rects: typing.Optional[typing.List[ScrollRect]] = None

    #: Sticky position constraint information
    sticky_position_constraint: typing.Optional[StickyPositionConstraint] = None

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["layerId"] = self.layer_id.to_json()
        json["offsetX"] = self.offset_x
        json["offsetY"] = self.offset_y
        json["width"] = self.width
        json["height"] = self.height
        json["paintCount"] = self.paint_count
        json["drawsContent"] = self.draws_content
        if self.parent_layer_id is not None:
            json["parentLayerId"] = self.parent_layer_id.to_json()
        if self.backend_node_id is not None:
            json["backendNodeId"] = self.backend_node_id.to_json()
        if self.transform is not None:
            json["transform"] = [i for i in self.transform]
        if self.anchor_x is not None:
            json["anchorX"] = self.anchor_x
        if self.anchor_y is not None:
            json["anchorY"] = self.anchor_y
        if self.anchor_z is not None:
            json["anchorZ"] = self.anchor_z
        if self.invisible is not None:
            json["invisible"] = self.invisible
        if self.scroll_rects is not None:
            json["scrollRects"] = [i.to_json() for i in self.scroll_rects]
        if self.sticky_position_constraint is not None:
            json["stickyPositionConstraint"] = self.sticky_position_constraint.to_json()
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> Layer:
        return cls(
            layer_id=LayerId.from_json(json["layerId"]),
            offset_x=float(json["offsetX"]),
            offset_y=float(json["offsetY"]),
            width=float(json["width"]),
            height=float(json["height"]),
            paint_count=int(json["paintCount"]),
            draws_content=bool(json["drawsContent"]),
            parent_layer_id=LayerId.from_json(json["parentLayerId"])
            if json.get("parentLayerId", None) is not None
            else None,
            backend_node_id=dom.BackendNodeId.from_json(json["backendNodeId"])
            if json.get("backendNodeId", None) is not None
            else None,
            transform=[float(i) for i in json["transform"]]
            if json.get("transform", None) is not None
            else None,
            anchor_x=float(json["anchorX"])
            if json.get("anchorX", None) is not None
            else None,
            anchor_y=float(json["anchorY"])
            if json.get("anchorY", None) is not None
            else None,
            anchor_z=float(json["anchorZ"])
            if json.get("anchorZ", None) is not None
            else None,
            invisible=bool(json["invisible"])
            if json.get("invisible", None) is not None
            else None,
            scroll_rects=[ScrollRect.from_json(i) for i in json["scrollRects"]]
            if json.get("scrollRects", None) is not None
            else None,
            sticky_position_constraint=StickyPositionConstraint.from_json(
                json["stickyPositionConstraint"]
            )
            if json.get("stickyPositionConstraint", None) is not None
            else None,
        )

anchor_x: typing.Optional[float] = None class-attribute instance-attribute

anchor_y: typing.Optional[float] = None class-attribute instance-attribute

anchor_z: typing.Optional[float] = None class-attribute instance-attribute

backend_node_id: typing.Optional[dom.BackendNodeId] = None class-attribute instance-attribute

draws_content: bool instance-attribute

height: float instance-attribute

invisible: typing.Optional[bool] = None class-attribute instance-attribute

layer_id: LayerId instance-attribute

offset_x: float instance-attribute

offset_y: float instance-attribute

paint_count: int instance-attribute

parent_layer_id: typing.Optional[LayerId] = None class-attribute instance-attribute

scroll_rects: typing.Optional[typing.List[ScrollRect]] = None class-attribute instance-attribute

sticky_position_constraint: typing.Optional[StickyPositionConstraint] = None class-attribute instance-attribute

transform: typing.Optional[typing.List[float]] = None class-attribute instance-attribute

width: float instance-attribute

__init__(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)

from_json(json) classmethod

Source code in zendriver/cdp/layer_tree.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> Layer:
    return cls(
        layer_id=LayerId.from_json(json["layerId"]),
        offset_x=float(json["offsetX"]),
        offset_y=float(json["offsetY"]),
        width=float(json["width"]),
        height=float(json["height"]),
        paint_count=int(json["paintCount"]),
        draws_content=bool(json["drawsContent"]),
        parent_layer_id=LayerId.from_json(json["parentLayerId"])
        if json.get("parentLayerId", None) is not None
        else None,
        backend_node_id=dom.BackendNodeId.from_json(json["backendNodeId"])
        if json.get("backendNodeId", None) is not None
        else None,
        transform=[float(i) for i in json["transform"]]
        if json.get("transform", None) is not None
        else None,
        anchor_x=float(json["anchorX"])
        if json.get("anchorX", None) is not None
        else None,
        anchor_y=float(json["anchorY"])
        if json.get("anchorY", None) is not None
        else None,
        anchor_z=float(json["anchorZ"])
        if json.get("anchorZ", None) is not None
        else None,
        invisible=bool(json["invisible"])
        if json.get("invisible", None) is not None
        else None,
        scroll_rects=[ScrollRect.from_json(i) for i in json["scrollRects"]]
        if json.get("scrollRects", None) is not None
        else None,
        sticky_position_constraint=StickyPositionConstraint.from_json(
            json["stickyPositionConstraint"]
        )
        if json.get("stickyPositionConstraint", None) is not None
        else None,
    )

to_json()

Source code in zendriver/cdp/layer_tree.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["layerId"] = self.layer_id.to_json()
    json["offsetX"] = self.offset_x
    json["offsetY"] = self.offset_y
    json["width"] = self.width
    json["height"] = self.height
    json["paintCount"] = self.paint_count
    json["drawsContent"] = self.draws_content
    if self.parent_layer_id is not None:
        json["parentLayerId"] = self.parent_layer_id.to_json()
    if self.backend_node_id is not None:
        json["backendNodeId"] = self.backend_node_id.to_json()
    if self.transform is not None:
        json["transform"] = [i for i in self.transform]
    if self.anchor_x is not None:
        json["anchorX"] = self.anchor_x
    if self.anchor_y is not None:
        json["anchorY"] = self.anchor_y
    if self.anchor_z is not None:
        json["anchorZ"] = self.anchor_z
    if self.invisible is not None:
        json["invisible"] = self.invisible
    if self.scroll_rects is not None:
        json["scrollRects"] = [i.to_json() for i in self.scroll_rects]
    if self.sticky_position_constraint is not None:
        json["stickyPositionConstraint"] = self.sticky_position_constraint.to_json()
    return json

LayerId

Bases: str

Unique Layer identifier.

Source code in zendriver/cdp/layer_tree.py
class LayerId(str):
    """
    Unique Layer identifier.
    """

    def to_json(self) -> str:
        return self

    @classmethod
    def from_json(cls, json: str) -> LayerId:
        return cls(json)

    def __repr__(self):
        return "LayerId({})".format(super().__repr__())

__repr__()

Source code in zendriver/cdp/layer_tree.py
def __repr__(self):
    return "LayerId({})".format(super().__repr__())

from_json(json) classmethod

Source code in zendriver/cdp/layer_tree.py
@classmethod
def from_json(cls, json: str) -> LayerId:
    return cls(json)

to_json()

Source code in zendriver/cdp/layer_tree.py
def to_json(self) -> str:
    return self

LayerPainted dataclass

Source code in zendriver/cdp/layer_tree.py
@event_class("LayerTree.layerPainted")
@dataclass
class LayerPainted:
    #: The id of the painted layer.
    layer_id: LayerId
    #: Clip rectangle.
    clip: dom.Rect

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> LayerPainted:
        return cls(
            layer_id=LayerId.from_json(json["layerId"]),
            clip=dom.Rect.from_json(json["clip"]),
        )

clip: dom.Rect instance-attribute

layer_id: LayerId instance-attribute

__init__(layer_id, clip)

from_json(json) classmethod

Source code in zendriver/cdp/layer_tree.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> LayerPainted:
    return cls(
        layer_id=LayerId.from_json(json["layerId"]),
        clip=dom.Rect.from_json(json["clip"]),
    )

LayerTreeDidChange dataclass

Source code in zendriver/cdp/layer_tree.py
@event_class("LayerTree.layerTreeDidChange")
@dataclass
class LayerTreeDidChange:
    #: Layer tree, absent if not in the compositing mode.
    layers: typing.Optional[typing.List[Layer]]

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> LayerTreeDidChange:
        return cls(
            layers=[Layer.from_json(i) for i in json["layers"]]
            if json.get("layers", None) is not None
            else None
        )

layers: typing.Optional[typing.List[Layer]] instance-attribute

__init__(layers)

from_json(json) classmethod

Source code in zendriver/cdp/layer_tree.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> LayerTreeDidChange:
    return cls(
        layers=[Layer.from_json(i) for i in json["layers"]]
        if json.get("layers", None) is not None
        else None
    )

PaintProfile

Bases: list

Array of timings, one per paint step.

Source code in zendriver/cdp/layer_tree.py
class PaintProfile(list):
    """
    Array of timings, one per paint step.
    """

    def to_json(self) -> typing.List[float]:
        return self

    @classmethod
    def from_json(cls, json: typing.List[float]) -> PaintProfile:
        return cls(json)

    def __repr__(self):
        return "PaintProfile({})".format(super().__repr__())

__repr__()

Source code in zendriver/cdp/layer_tree.py
def __repr__(self):
    return "PaintProfile({})".format(super().__repr__())

from_json(json) classmethod

Source code in zendriver/cdp/layer_tree.py
@classmethod
def from_json(cls, json: typing.List[float]) -> PaintProfile:
    return cls(json)

to_json()

Source code in zendriver/cdp/layer_tree.py
def to_json(self) -> typing.List[float]:
    return self

PictureTile dataclass

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

Source code in zendriver/cdp/layer_tree.py
@dataclass
class PictureTile:
    """
    Serialized fragment of layer picture along with its offset within the layer.
    """

    #: Offset from owning layer left boundary
    x: float

    #: Offset from owning layer top boundary
    y: float

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

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["x"] = self.x
        json["y"] = self.y
        json["picture"] = self.picture
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PictureTile:
        return cls(
            x=float(json["x"]),
            y=float(json["y"]),
            picture=str(json["picture"]),
        )

picture: str instance-attribute

x: float instance-attribute

y: float instance-attribute

__init__(x, y, picture)

from_json(json) classmethod

Source code in zendriver/cdp/layer_tree.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PictureTile:
    return cls(
        x=float(json["x"]),
        y=float(json["y"]),
        picture=str(json["picture"]),
    )

to_json()

Source code in zendriver/cdp/layer_tree.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["x"] = self.x
    json["y"] = self.y
    json["picture"] = self.picture
    return json

ScrollRect dataclass

Rectangle where scrolling happens on the main thread.

Source code in zendriver/cdp/layer_tree.py
@dataclass
class ScrollRect:
    """
    Rectangle where scrolling happens on the main thread.
    """

    #: Rectangle itself.
    rect: dom.Rect

    #: Reason for rectangle to force scrolling on the main thread
    type_: str

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["rect"] = self.rect.to_json()
        json["type"] = self.type_
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> ScrollRect:
        return cls(
            rect=dom.Rect.from_json(json["rect"]),
            type_=str(json["type"]),
        )

rect: dom.Rect instance-attribute

type_: str instance-attribute

__init__(rect, type_)

from_json(json) classmethod

Source code in zendriver/cdp/layer_tree.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> ScrollRect:
    return cls(
        rect=dom.Rect.from_json(json["rect"]),
        type_=str(json["type"]),
    )

to_json()

Source code in zendriver/cdp/layer_tree.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["rect"] = self.rect.to_json()
    json["type"] = self.type_
    return json

SnapshotId

Bases: str

Unique snapshot identifier.

Source code in zendriver/cdp/layer_tree.py
class SnapshotId(str):
    """
    Unique snapshot identifier.
    """

    def to_json(self) -> str:
        return self

    @classmethod
    def from_json(cls, json: str) -> SnapshotId:
        return cls(json)

    def __repr__(self):
        return "SnapshotId({})".format(super().__repr__())

__repr__()

Source code in zendriver/cdp/layer_tree.py
def __repr__(self):
    return "SnapshotId({})".format(super().__repr__())

from_json(json) classmethod

Source code in zendriver/cdp/layer_tree.py
@classmethod
def from_json(cls, json: str) -> SnapshotId:
    return cls(json)

to_json()

Source code in zendriver/cdp/layer_tree.py
def to_json(self) -> str:
    return self

StickyPositionConstraint dataclass

Sticky position constraints.

Source code in zendriver/cdp/layer_tree.py
@dataclass
class StickyPositionConstraint:
    """
    Sticky position constraints.
    """

    #: Layout rectangle of the sticky element before being shifted
    sticky_box_rect: dom.Rect

    #: Layout rectangle of the containing block of the sticky element
    containing_block_rect: dom.Rect

    #: The nearest sticky layer that shifts the sticky box
    nearest_layer_shifting_sticky_box: typing.Optional[LayerId] = None

    #: The nearest sticky layer that shifts the containing block
    nearest_layer_shifting_containing_block: typing.Optional[LayerId] = None

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["stickyBoxRect"] = self.sticky_box_rect.to_json()
        json["containingBlockRect"] = self.containing_block_rect.to_json()
        if self.nearest_layer_shifting_sticky_box is not None:
            json["nearestLayerShiftingStickyBox"] = (
                self.nearest_layer_shifting_sticky_box.to_json()
            )
        if self.nearest_layer_shifting_containing_block is not None:
            json["nearestLayerShiftingContainingBlock"] = (
                self.nearest_layer_shifting_containing_block.to_json()
            )
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> StickyPositionConstraint:
        return cls(
            sticky_box_rect=dom.Rect.from_json(json["stickyBoxRect"]),
            containing_block_rect=dom.Rect.from_json(json["containingBlockRect"]),
            nearest_layer_shifting_sticky_box=LayerId.from_json(
                json["nearestLayerShiftingStickyBox"]
            )
            if json.get("nearestLayerShiftingStickyBox", None) is not None
            else None,
            nearest_layer_shifting_containing_block=LayerId.from_json(
                json["nearestLayerShiftingContainingBlock"]
            )
            if json.get("nearestLayerShiftingContainingBlock", None) is not None
            else None,
        )

containing_block_rect: dom.Rect instance-attribute

nearest_layer_shifting_containing_block: typing.Optional[LayerId] = None class-attribute instance-attribute

nearest_layer_shifting_sticky_box: typing.Optional[LayerId] = None class-attribute instance-attribute

sticky_box_rect: dom.Rect instance-attribute

__init__(sticky_box_rect, containing_block_rect, nearest_layer_shifting_sticky_box=None, nearest_layer_shifting_containing_block=None)

from_json(json) classmethod

Source code in zendriver/cdp/layer_tree.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> StickyPositionConstraint:
    return cls(
        sticky_box_rect=dom.Rect.from_json(json["stickyBoxRect"]),
        containing_block_rect=dom.Rect.from_json(json["containingBlockRect"]),
        nearest_layer_shifting_sticky_box=LayerId.from_json(
            json["nearestLayerShiftingStickyBox"]
        )
        if json.get("nearestLayerShiftingStickyBox", None) is not None
        else None,
        nearest_layer_shifting_containing_block=LayerId.from_json(
            json["nearestLayerShiftingContainingBlock"]
        )
        if json.get("nearestLayerShiftingContainingBlock", None) is not None
        else None,
    )

to_json()

Source code in zendriver/cdp/layer_tree.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["stickyBoxRect"] = self.sticky_box_rect.to_json()
    json["containingBlockRect"] = self.containing_block_rect.to_json()
    if self.nearest_layer_shifting_sticky_box is not None:
        json["nearestLayerShiftingStickyBox"] = (
            self.nearest_layer_shifting_sticky_box.to_json()
        )
    if self.nearest_layer_shifting_containing_block is not None:
        json["nearestLayerShiftingContainingBlock"] = (
            self.nearest_layer_shifting_containing_block.to_json()
        )
    return json

compositing_reasons(layer_id)

Provides the reasons why the given layer was composited.

Parameters:

Name Type Description Default
layer_id LayerId

The id of the layer for which we want to get the reasons it was composited.

required

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, Tuple[List[str], List[str]]]

A tuple with the following items: 0. compositingReasons - A list of strings specifying reasons for the given layer to become composited. 1. compositingReasonIds - A list of strings specifying reason IDs for the given layer to become composited.

Source code in zendriver/cdp/layer_tree.py
def compositing_reasons(
    layer_id: LayerId,
) -> typing.Generator[
    T_JSON_DICT, T_JSON_DICT, typing.Tuple[typing.List[str], typing.List[str]]
]:
    """
    Provides the reasons why the given layer was composited.

    :param layer_id: The id of the layer for which we want to get the reasons it was composited.
    :returns: A tuple with the following items:

        0. **compositingReasons** - A list of strings specifying reasons for the given layer to become composited.
        1. **compositingReasonIds** - A list of strings specifying reason IDs for the given layer to become composited.
    """
    params: T_JSON_DICT = dict()
    params["layerId"] = layer_id.to_json()
    cmd_dict: T_JSON_DICT = {
        "method": "LayerTree.compositingReasons",
        "params": params,
    }
    json = yield cmd_dict
    return (
        [str(i) for i in json["compositingReasons"]],
        [str(i) for i in json["compositingReasonIds"]],
    )

disable()

Disables compositing tree inspection.

Source code in zendriver/cdp/layer_tree.py
def disable() -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Disables compositing tree inspection.
    """
    cmd_dict: T_JSON_DICT = {
        "method": "LayerTree.disable",
    }
    json = yield cmd_dict

enable()

Enables compositing tree inspection.

Source code in zendriver/cdp/layer_tree.py
def enable() -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Enables compositing tree inspection.
    """
    cmd_dict: T_JSON_DICT = {
        "method": "LayerTree.enable",
    }
    json = yield cmd_dict

load_snapshot(tiles)

Returns the snapshot identifier.

Parameters:

Name Type Description Default
tiles List[PictureTile]

An array of tiles composing the snapshot.

required

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, SnapshotId]

The id of the snapshot.

Source code in zendriver/cdp/layer_tree.py
def load_snapshot(
    tiles: typing.List[PictureTile],
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, SnapshotId]:
    """
    Returns the snapshot identifier.

    :param tiles: An array of tiles composing the snapshot.
    :returns: The id of the snapshot.
    """
    params: T_JSON_DICT = dict()
    params["tiles"] = [i.to_json() for i in tiles]
    cmd_dict: T_JSON_DICT = {
        "method": "LayerTree.loadSnapshot",
        "params": params,
    }
    json = yield cmd_dict
    return SnapshotId.from_json(json["snapshotId"])

make_snapshot(layer_id)

Returns the layer snapshot identifier.

Parameters:

Name Type Description Default
layer_id LayerId

The id of the layer.

required

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, SnapshotId]

The id of the layer snapshot.

Source code in zendriver/cdp/layer_tree.py
def make_snapshot(
    layer_id: LayerId,
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, SnapshotId]:
    """
    Returns the layer snapshot identifier.

    :param layer_id: The id of the layer.
    :returns: The id of the layer snapshot.
    """
    params: T_JSON_DICT = dict()
    params["layerId"] = layer_id.to_json()
    cmd_dict: T_JSON_DICT = {
        "method": "LayerTree.makeSnapshot",
        "params": params,
    }
    json = yield cmd_dict
    return SnapshotId.from_json(json["snapshotId"])

profile_snapshot(snapshot_id, min_repeat_count=None, min_duration=None, clip_rect=None)

Parameters:

Name Type Description Default
snapshot_id SnapshotId

The id of the layer snapshot.

required
min_repeat_count Optional[int]

(Optional) The maximum number of times to replay the snapshot (1, if not specified).

None
min_duration Optional[float]

(Optional) The minimum duration (in seconds) to replay the snapshot.

None
clip_rect Optional[Rect]

(Optional) The clip rectangle to apply when replaying the snapshot.

None

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, List[PaintProfile]]

The array of paint profiles, one per run.

Source code in zendriver/cdp/layer_tree.py
def profile_snapshot(
    snapshot_id: SnapshotId,
    min_repeat_count: typing.Optional[int] = None,
    min_duration: typing.Optional[float] = None,
    clip_rect: typing.Optional[dom.Rect] = None,
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, typing.List[PaintProfile]]:
    """
    :param snapshot_id: The id of the layer snapshot.
    :param min_repeat_count: *(Optional)* The maximum number of times to replay the snapshot (1, if not specified).
    :param min_duration: *(Optional)* The minimum duration (in seconds) to replay the snapshot.
    :param clip_rect: *(Optional)* The clip rectangle to apply when replaying the snapshot.
    :returns: The array of paint profiles, one per run.
    """
    params: T_JSON_DICT = dict()
    params["snapshotId"] = snapshot_id.to_json()
    if min_repeat_count is not None:
        params["minRepeatCount"] = min_repeat_count
    if min_duration is not None:
        params["minDuration"] = min_duration
    if clip_rect is not None:
        params["clipRect"] = clip_rect.to_json()
    cmd_dict: T_JSON_DICT = {
        "method": "LayerTree.profileSnapshot",
        "params": params,
    }
    json = yield cmd_dict
    return [PaintProfile.from_json(i) for i in json["timings"]]

release_snapshot(snapshot_id)

Releases layer snapshot captured by the back-end.

Parameters:

Name Type Description Default
snapshot_id SnapshotId

The id of the layer snapshot.

required
Source code in zendriver/cdp/layer_tree.py
def release_snapshot(
    snapshot_id: SnapshotId,
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Releases layer snapshot captured by the back-end.

    :param snapshot_id: The id of the layer snapshot.
    """
    params: T_JSON_DICT = dict()
    params["snapshotId"] = snapshot_id.to_json()
    cmd_dict: T_JSON_DICT = {
        "method": "LayerTree.releaseSnapshot",
        "params": params,
    }
    json = yield cmd_dict

replay_snapshot(snapshot_id, from_step=None, to_step=None, scale=None)

Replays the layer snapshot and returns the resulting bitmap.

Parameters:

Name Type Description Default
snapshot_id SnapshotId

The id of the layer snapshot.

required
from_step Optional[int]

(Optional) The first step to replay from (replay from the very start if not specified).

None
to_step Optional[int]

(Optional) The last step to replay to (replay till the end if not specified).

None
scale Optional[float]

(Optional) The scale to apply while replaying (defaults to 1).

None

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, str]

A data: URL for resulting image.

Source code in zendriver/cdp/layer_tree.py
def replay_snapshot(
    snapshot_id: SnapshotId,
    from_step: typing.Optional[int] = None,
    to_step: typing.Optional[int] = None,
    scale: typing.Optional[float] = None,
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, str]:
    """
    Replays the layer snapshot and returns the resulting bitmap.

    :param snapshot_id: The id of the layer snapshot.
    :param from_step: *(Optional)* The first step to replay from (replay from the very start if not specified).
    :param to_step: *(Optional)* The last step to replay to (replay till the end if not specified).
    :param scale: *(Optional)* The scale to apply while replaying (defaults to 1).
    :returns: A data: URL for resulting image.
    """
    params: T_JSON_DICT = dict()
    params["snapshotId"] = snapshot_id.to_json()
    if from_step is not None:
        params["fromStep"] = from_step
    if to_step is not None:
        params["toStep"] = to_step
    if scale is not None:
        params["scale"] = scale
    cmd_dict: T_JSON_DICT = {
        "method": "LayerTree.replaySnapshot",
        "params": params,
    }
    json = yield cmd_dict
    return str(json["dataURL"])

snapshot_command_log(snapshot_id)

Replays the layer snapshot and returns canvas log.

Parameters:

Name Type Description Default
snapshot_id SnapshotId

The id of the layer snapshot.

required

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, List[dict]]

The array of canvas function calls.

Source code in zendriver/cdp/layer_tree.py
def snapshot_command_log(
    snapshot_id: SnapshotId,
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, typing.List[dict]]:
    """
    Replays the layer snapshot and returns canvas log.

    :param snapshot_id: The id of the layer snapshot.
    :returns: The array of canvas function calls.
    """
    params: T_JSON_DICT = dict()
    params["snapshotId"] = snapshot_id.to_json()
    cmd_dict: T_JSON_DICT = {
        "method": "LayerTree.snapshotCommandLog",
        "params": params,
    }
    json = yield cmd_dict
    return [dict(i) for i in json["commandLog"]]