扩展类
🌐 Extension class
Extension 表示安装在浏览器中的浏览器扩展。它提供了访问扩展的 ID、名称和版本的方法,以及与扩展的后台工作程序和页面交互的方法。
语法
🌐 Signature
export declare abstract class Extension
附注
🌐 Remarks
这个类的构造函数被标记为内部。第三方代码不应直接调用构造函数或创建继承 Extension 类的子类。
🌐 The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the Extension class.
示例
🌐 Example
要在浏览器中安装所有扩展程序:
🌐 To get all extensions installed in the browser:
const extensions = await browser.extensions();
for (const [id, extension] of extensions) {
console.log(extension.name, id);
}
属性
🌐 Properties
属性 🌐 Property | 修饰符 🌐 Modifiers | 类型 🌐 Type | 描述 🌐 Description |
|---|---|---|---|
| enabled |
| boolean | 扩展是否已启用。 🌐 Whether the extension is enabled. |
| id |
| string | 扩展的唯一标识符。 🌐 The unique identifier of the extension. |
| name |
| string | 扩展程序在其清单中指定的名称。 🌐 The name of the extension as specified in its manifest. |
| path |
| string | 扩展所在的文件系统路径。 🌐 The path in the file system where the extension is located. |
| version |
| string | 扩展程序在其清单中指定的版本。 🌐 The version of the extension as specified in its manifest. |
方法
🌐 Methods
方法 🌐 Method | 修饰符 🌐 Modifiers | 描述 🌐 Description |
|---|---|---|
| pages() | 返回属于该扩展程序的当前活动且可见的页面列表。 🌐 Returns a list of the currently active and visible pages belonging to the extension. | |
| triggerAction(page) | 触发指定页面的扩展默认操作。这通常模拟用户点击浏览器工具栏中扩展的操作图标,可能会打开弹出窗口或执行操作脚本。 🌐 Triggers the default action of the extension for a specified page. This typically simulates a user clicking the extension's action icon in the browser toolbar, potentially opening a popup or executing an action script. | |
| workers() | 返回属于该扩展程序的当前活动服务工作线程的列表。 🌐 Returns a list of the currently active service workers belonging to the extension. |