Installs Firefox addon. Returns identifier of installed addon. This identifier can later be used to uninstall addon. .. deprecated:: 4.52 Use `install_web_extension` instead, which works on every browser that supports web extensions and returns a `We
(self, path, temporary=False)
| 103 | self.set_context(initial_context) |
| 104 | |
| 105 | def install_addon(self, path, temporary=False) -> str: |
| 106 | """Installs Firefox addon. |
| 107 | |
| 108 | Returns identifier of installed addon. This identifier can later |
| 109 | be used to uninstall addon. |
| 110 | |
| 111 | .. deprecated:: 4.52 |
| 112 | Use `install_web_extension` instead, which works on every browser |
| 113 | that supports web extensions and returns a `WebExtension` object. |
| 114 | |
| 115 | Args: |
| 116 | path: Absolute path to the addon that will be installed. |
| 117 | temporary: Allows you to load browser extensions temporarily during a session. |
| 118 | |
| 119 | Returns: |
| 120 | Identifier of installed addon. |
| 121 | |
| 122 | Example: |
| 123 | driver.install_addon("/path/to/firebug.xpi") |
| 124 | """ |
| 125 | warnings.warn( |
| 126 | "install_addon is deprecated, use install_web_extension instead", |
| 127 | DeprecationWarning, |
| 128 | stacklevel=2, |
| 129 | ) |
| 130 | if os.path.isdir(path): |
| 131 | fp = BytesIO() |
| 132 | # filter all trailing slash found in path |
| 133 | path = os.path.normpath(path) |
| 134 | # account for trailing slash that will be added by os.walk() |
| 135 | path_root = len(path) + 1 |
| 136 | with zipfile.ZipFile(fp, "w", zipfile.ZIP_DEFLATED, strict_timestamps=False) as zipped: |
| 137 | for base, _, files in os.walk(path): |
| 138 | for fyle in files: |
| 139 | filename = os.path.join(base, fyle) |
| 140 | zipped.write(filename, filename[path_root:]) |
| 141 | addon = base64.b64encode(fp.getvalue()).decode("UTF-8") |
| 142 | else: |
| 143 | with open(path, "rb") as file: |
| 144 | addon = base64.b64encode(file.read()).decode("UTF-8") |
| 145 | |
| 146 | payload = {"addon": addon, "temporary": temporary} |
| 147 | return self.execute("INSTALL_ADDON", payload)["value"] |
| 148 | |
| 149 | def uninstall_addon(self, identifier) -> None: |
| 150 | """Uninstalls Firefox addon using its identifier. |