WebExtension#

Added in version 2.52.

class WebExtension(**properties: Any)#

Superclasses: Object

Implemented Interfaces: Initable

Represents a WebExtension.

A WebExtension object encapsulates a web extension’s resources that are defined by a `manifest.json file <https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json>`__.

This class handles the reading and parsing of the manifest file along with the supporting resources like icons and localizations.

Constructors#

class WebExtension
classmethod new(extension_path: str) WebExtension | None#

Creates a new WebKitWebExtension from a folder containing the extension contents. The folder must contain a manifest.json file. If the manifest is invalid or missing, an error will be returned.

Added in version 2.52.

Parameters:

extension_path – A string pointing to the folder containing the extension manifest and resources

Methods#

class WebExtension
get_action_icon(width: float, height: float) Icon | None#

Returns the extension’s default action icon image for the specified size. This icon serves as a default and should be used to represent the extension in contexts like action sheets or toolbars prior to the extension being loaded into an extension context. Once the extension is loaded, use the actionForTab: API to get the tab-specific icon. The returned image will be the best match for the specified size that is available in the extension’s action icon set. If no matching icon is available, the method will fall back to the extension’s icon.

Added in version 2.52.

Parameters:
  • width – The width to use when looking up the icon.

  • height – The height to use when looking up the icon.

get_all_requested_match_patterns() list[WebExtensionMatchPattern]#

Get the set of websites that the extension requires access to for injected content and for receiving messages from websites.

Added in version 2.52.

get_default_locale() str | None#

Get the default locale for the extension.

Added in version 2.52.

get_display_action_label() str | None#

Get the localized display action label for the extension.

This label serves as a default and should be used to represent the extension in contexts like action sheets or toolbars prior to the extension being loaded into an extension context. Once the extension is loaded, use the actionForTab: API to get the tab-specific label.

Added in version 2.52.

get_display_description() str | None#

Get the localized display description for the extension.

Added in version 2.52.

get_display_name() str | None#

Get the localized name for the extension.

Added in version 2.52.

get_display_short_name() str | None#

Get the localized short name for the extension.

Added in version 2.52.

get_display_version() str | None#

Get the localized display version for the extension.

Added in version 2.52.

get_has_background_content() bool#

Get whether the extension has background content that can run when needed.

Added in version 2.52.

get_has_commands() bool#

Get whether the extension includes commands that users can invoke.

These commands should be accessible via keyboard shortcuts, menu items, or other user interface elements provided by the app. The list of commands can be accessed via commands on an extension context, and invoked via performCommand:.

Added in version 2.52.

get_has_content_modification_rules() bool#

Get whether the extension includes rules used for content modification or blocking.

Added in version 2.52.

get_has_injected_content() bool#

Get whether the extension has script or stylesheet content that can be injected into webpages.

Once the extension is loaded, use the hasInjectedContent property on an extension context, as the injectable content can change after the extension is loaded.

Added in version 2.52.

get_has_options_page() bool#

Get whether the extension has an options page.

The app should provide access to this page through a user interface element, which can be accessed via optionsPageURL on an extension context.

Added in version 2.52.

get_has_override_new_tab_page() bool#

Get whether the extension provides an alternative to the default new tab page.

The app should prompt the user for permission to use the extension’s new tab page as the default, which can be accessed via overrideNewTabPageURL on an extension context.

Added in version 2.52.

get_has_persistent_background_content() bool#

Get whether the extension has background content that stays in memory as long as the extension is loaded.

Added in version 2.52.

get_icon(width: float, height: float) Icon | None#

Returns the extension’s icon image for the specified size. This icon should represent the extension in settings or other areas that show the extension. The returned image will be the best match for the specified size that is available in the extension’s icon set. If no matching icon can be found, the method will return None.

Added in version 2.52.

Parameters:
  • width – The width to use when looking up the icon.

  • height – The height to use when looking up the icon.

get_manifest_version() float#

Get the parsed manifest version, or 0 if there is no version specified in the manifest.

A UNSUPPORTED_MANIFEST_VERSION error will be reported if the manifest version isn’t specified.

Added in version 2.52.

get_optional_permission_match_patterns() list[WebExtensionMatchPattern]#

Get the set of websites that the extension may need access to for optional functionality. These match patterns can be requested by the extension at a later time.

Added in version 2.52.

get_optional_permissions() list[str] | None#

Get the set of permissions that the extension may need for optional functionality. These permissions can be requested by the extension at a later time.

Added in version 2.52.

get_path() str#

Get the path pointing to the folder containing the extension manifest and resources

Added in version 2.52.

get_requested_permission_match_patterns() list[WebExtensionMatchPattern]#

Get the set of websites that the extension requires access to for its base functionality.

Added in version 2.52.

get_requested_permissions() list[str] | None#

Get the set of permissions that the extension requires for its base functionality.

Added in version 2.52.

get_version() str | None#

Get the version for the extension.

Added in version 2.52.

supports_manifest_version(manifest_version: float) bool#

Checks if a manifest version is supported by the extension.

Added in version 2.52.

Parameters:

manifest_version – the version number to check

Properties#

class WebExtension
props.default_locale: str#

The default locale for the WebExtension. See get_default_locale() for more details.

Added in version 2.52.

props.display_action_label: str#

The localized extension action label of the WebExtension. See get_display_action_label() for more details.

Added in version 2.52.

props.display_description: str#

The localized description of the WebExtension. See get_display_description() for more details.

Added in version 2.52.

props.display_name: str#

The localized name of the WebExtension. See get_display_name() for more details.

Added in version 2.52.

props.display_short_name: str#

The localized short name of the WebExtension. See get_display_short_name() for more details.

Added in version 2.52.

props.display_version: str#

The localized display version of the WebExtension. See get_display_version() for more details.

Added in version 2.52.

props.has_background_content: bool#

Whether the WebExtension has background content that can run when needed. See get_has_background_content() for more details.

Added in version 2.52.

props.has_commands: bool#

Whether the WebExtension includes commands that users can invoke. See get_has_commands() for more details.

Added in version 2.52.

props.has_content_modification_rules: bool#

Whether the WebExtension includes rules used for content modification or blocking. See webkit_web_extension_get_content_modification_rules() for more details.

Added in version 2.52.

props.has_injected_content: bool#

Whether the WebExtension has script or stylesheet content that can be injected into webpages. See get_has_injected_content() for more details.

Added in version 2.52.

props.has_options_page: bool#

Whether the WebExtension has an options page. See get_has_options_page() for more details.

Added in version 2.52.

props.has_override_new_tab_page: bool#

Whether the WebExtension provides an alternative to the default new tab page. See get_has_override_new_tab_page() for more details.

Added in version 2.52.

props.has_persistent_background_content: bool#

Whether the WebExtension has background content that stays in memory as long as the extension is loaded. See get_has_persistent_background_content() for more details.

Added in version 2.52.

props.manifest_version: str#

The parsed manifest version of the WebExtension. See get_manifest_version() for more details.

Added in version 2.52.

props.optional_permissions: list[str]#

The set of permissions that the WebExtension may need for optional functionality. See get_optional_permissions() for more details.

Added in version 2.52.

props.path: str#

A string pointing to the folder containing the extension manifest and resources. See get_path() for more details.

Added in version 2.52.

props.requested_permissions: list[str]#

The set of permissions that the WebExtension requires for its base functionality. See get_requested_permissions() for more details.

Added in version 2.52.

props.version: str#

The version of the WebExtension. See get_version() for more details.

Added in version 2.52.