Skip to content

extensions

ExtensionInfo dataclass

Detailed information about an extension.

Source code in zendriver/cdp/extensions.py
@dataclass
class ExtensionInfo:
    """
    Detailed information about an extension.
    """

    #: Extension id.
    id_: str

    #: Extension name.
    name: str

    #: Extension version.
    version: str

    #: The path from which the extension was loaded.
    path: str

    #: Extension enabled status.
    enabled: bool

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["id"] = self.id_
        json["name"] = self.name
        json["version"] = self.version
        json["path"] = self.path
        json["enabled"] = self.enabled
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> ExtensionInfo:
        return cls(
            id_=str(json["id"]),
            name=str(json["name"]),
            version=str(json["version"]),
            path=str(json["path"]),
            enabled=bool(json["enabled"]),
        )

enabled: bool instance-attribute

id_: str instance-attribute

name: str instance-attribute

path: str instance-attribute

version: str instance-attribute

__init__(id_, name, version, path, enabled)

from_json(json) classmethod

Source code in zendriver/cdp/extensions.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> ExtensionInfo:
    return cls(
        id_=str(json["id"]),
        name=str(json["name"]),
        version=str(json["version"]),
        path=str(json["path"]),
        enabled=bool(json["enabled"]),
    )

to_json()

Source code in zendriver/cdp/extensions.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["id"] = self.id_
    json["name"] = self.name
    json["version"] = self.version
    json["path"] = self.path
    json["enabled"] = self.enabled
    return json

StorageArea

Bases: Enum

Storage areas.

Source code in zendriver/cdp/extensions.py
class StorageArea(enum.Enum):
    """
    Storage areas.
    """

    SESSION = "session"
    LOCAL = "local"
    SYNC = "sync"
    MANAGED = "managed"

    def to_json(self) -> str:
        return self.value

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

LOCAL = 'local' class-attribute instance-attribute

MANAGED = 'managed' class-attribute instance-attribute

SESSION = 'session' class-attribute instance-attribute

SYNC = 'sync' class-attribute instance-attribute

from_json(json) classmethod

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

to_json()

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

clear_storage_items(id_, storage_area)

Clears extension storage in the given storageArea.

Parameters:

Name Type Description Default
id_ str

ID of extension.

required
storage_area StorageArea

StorageArea to remove data from.

required
Source code in zendriver/cdp/extensions.py
def clear_storage_items(
    id_: str, storage_area: StorageArea
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Clears extension storage in the given ``storageArea``.

    :param id_: ID of extension.
    :param storage_area: StorageArea to remove data from.
    """
    params: T_JSON_DICT = dict()
    params["id"] = id_
    params["storageArea"] = storage_area.to_json()
    cmd_dict: T_JSON_DICT = {
        "method": "Extensions.clearStorageItems",
        "params": params,
    }
    json = yield cmd_dict

get_extensions()

Gets a list of all unpacked extensions. Available if the client is connected using the --remote-debugging-pipe flag and the --enable-unsafe-extension-debugging flag is set.

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, List[ExtensionInfo]]
Source code in zendriver/cdp/extensions.py
def get_extensions() -> (
    typing.Generator[T_JSON_DICT, T_JSON_DICT, typing.List[ExtensionInfo]]
):
    """
    Gets a list of all unpacked extensions.
    Available if the client is connected using the --remote-debugging-pipe flag
    and the --enable-unsafe-extension-debugging flag is set.

    :returns:
    """
    cmd_dict: T_JSON_DICT = {
        "method": "Extensions.getExtensions",
    }
    json = yield cmd_dict
    return [ExtensionInfo.from_json(i) for i in json["extensions"]]

get_storage_items(id_, storage_area, keys=None)

Gets data from extension storage in the given storageArea. If keys is specified, these are used to filter the result.

Parameters:

Name Type Description Default
id_ str

ID of extension.

required
storage_area StorageArea

StorageArea to retrieve data from.

required
keys Optional[List[str]]

(Optional) Keys to retrieve.

None

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, dict]
Source code in zendriver/cdp/extensions.py
def get_storage_items(
    id_: str, storage_area: StorageArea, keys: typing.Optional[typing.List[str]] = None
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, dict]:
    """
    Gets data from extension storage in the given ``storageArea``. If ``keys`` is
    specified, these are used to filter the result.

    :param id_: ID of extension.
    :param storage_area: StorageArea to retrieve data from.
    :param keys: *(Optional)* Keys to retrieve.
    :returns:
    """
    params: T_JSON_DICT = dict()
    params["id"] = id_
    params["storageArea"] = storage_area.to_json()
    if keys is not None:
        params["keys"] = [i for i in keys]
    cmd_dict: T_JSON_DICT = {
        "method": "Extensions.getStorageItems",
        "params": params,
    }
    json = yield cmd_dict
    return dict(json["data"])

load_unpacked(path, enable_in_incognito=None)

Installs an unpacked extension from the filesystem similar to --load-extension CLI flags. Returns extension ID once the extension has been installed. Available if the client is connected using the --remote-debugging-pipe flag and the --enable-unsafe-extension-debugging flag is set.

Parameters:

Name Type Description Default
path str

Absolute file path.

required
enable_in_incognito Optional[bool]

(Optional) Enable the extension in incognito

None

Returns:

Type Description
Generator[T_JSON_DICT, T_JSON_DICT, str]

Extension id.

Source code in zendriver/cdp/extensions.py
def load_unpacked(
    path: str, enable_in_incognito: typing.Optional[bool] = None
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, str]:
    """
    Installs an unpacked extension from the filesystem similar to
    --load-extension CLI flags. Returns extension ID once the extension
    has been installed. Available if the client is connected using the
    --remote-debugging-pipe flag and the --enable-unsafe-extension-debugging
    flag is set.

    :param path: Absolute file path.
    :param enable_in_incognito: *(Optional)* Enable the extension in incognito
    :returns: Extension id.
    """
    params: T_JSON_DICT = dict()
    params["path"] = path
    if enable_in_incognito is not None:
        params["enableInIncognito"] = enable_in_incognito
    cmd_dict: T_JSON_DICT = {
        "method": "Extensions.loadUnpacked",
        "params": params,
    }
    json = yield cmd_dict
    return str(json["id"])

remove_storage_items(id_, storage_area, keys)

Removes keys from extension storage in the given storageArea.

Parameters:

Name Type Description Default
id_ str

ID of extension.

required
storage_area StorageArea

StorageArea to remove data from.

required
keys List[str]

Keys to remove.

required
Source code in zendriver/cdp/extensions.py
def remove_storage_items(
    id_: str, storage_area: StorageArea, keys: typing.List[str]
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Removes ``keys`` from extension storage in the given ``storageArea``.

    :param id_: ID of extension.
    :param storage_area: StorageArea to remove data from.
    :param keys: Keys to remove.
    """
    params: T_JSON_DICT = dict()
    params["id"] = id_
    params["storageArea"] = storage_area.to_json()
    params["keys"] = [i for i in keys]
    cmd_dict: T_JSON_DICT = {
        "method": "Extensions.removeStorageItems",
        "params": params,
    }
    json = yield cmd_dict

set_storage_items(id_, storage_area, values)

Sets values in extension storage in the given storageArea. The provided values will be merged with existing values in the storage area.

Parameters:

Name Type Description Default
id_ str

ID of extension.

required
storage_area StorageArea

StorageArea to set data in.

required
values dict

Values to set.

required
Source code in zendriver/cdp/extensions.py
def set_storage_items(
    id_: str, storage_area: StorageArea, values: dict
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Sets ``values`` in extension storage in the given ``storageArea``. The provided ``values``
    will be merged with existing values in the storage area.

    :param id_: ID of extension.
    :param storage_area: StorageArea to set data in.
    :param values: Values to set.
    """
    params: T_JSON_DICT = dict()
    params["id"] = id_
    params["storageArea"] = storage_area.to_json()
    params["values"] = values
    cmd_dict: T_JSON_DICT = {
        "method": "Extensions.setStorageItems",
        "params": params,
    }
    json = yield cmd_dict

trigger_action(id_, target_id)

Runs an extension default action. Available if the client is connected using the --remote-debugging-pipe flag and the --enable-unsafe-extension-debugging flag is set.

Parameters:

Name Type Description Default
id_ str

Extension id.

required
target_id str

A tab target ID to trigger the default extension action on.

required
Source code in zendriver/cdp/extensions.py
def trigger_action(
    id_: str, target_id: str
) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Runs an extension default action.
    Available if the client is connected using the --remote-debugging-pipe
    flag and the --enable-unsafe-extension-debugging flag is set.

    :param id_: Extension id.
    :param target_id: A tab target ID to trigger the default extension action on.
    """
    params: T_JSON_DICT = dict()
    params["id"] = id_
    params["targetId"] = target_id
    cmd_dict: T_JSON_DICT = {
        "method": "Extensions.triggerAction",
        "params": params,
    }
    json = yield cmd_dict

uninstall(id_)

Uninstalls an unpacked extension (others not supported) from the profile. Available if the client is connected using the --remote-debugging-pipe flag and the --enable-unsafe-extension-debugging.

Parameters:

Name Type Description Default
id_ str

Extension id.

required
Source code in zendriver/cdp/extensions.py
def uninstall(id_: str) -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Uninstalls an unpacked extension (others not supported) from the profile.
    Available if the client is connected using the --remote-debugging-pipe flag
    and the --enable-unsafe-extension-debugging.

    :param id_: Extension id.
    """
    params: T_JSON_DICT = dict()
    params["id"] = id_
    cmd_dict: T_JSON_DICT = {
        "method": "Extensions.uninstall",
        "params": params,
    }
    json = yield cmd_dict