Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"includes": [
"src/**/*.{ts,tsx,js,jsx}",
"**/*.{json,jsonc,md,mdx,cjs,mjs}",
"!dist/**/*"
"!dist/**/*",
"!addon/**/*"
]
},
"formatter": {
Expand Down
94 changes: 72 additions & 22 deletions docs/sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@ Documentation:
- [Opera Sidebar Action API](https://help.opera.com/en/extensions/sidebar-action-api/)
- [Firefox Sidebar Action API](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/sidebarAction)

A promise-based wrapper around Chrome's side panel (`chrome.sidePanel`, MV3) and Firefox/Opera `sidebarAction` APIs. Methods provide unified behavior to get/set options and behavior, open the panel, and, where supported, manage title and icon (Firefox & Opera) and badge (Opera).
A promise-based wrapper around Chromium's side panel (`chrome.sidePanel`, MV3) and Firefox/Opera `sidebarAction` APIs. Methods provide unified behavior to get/set options and behavior, open the panel, and, where supported, manage title and icon (Firefox & Opera) and badge (Opera). Support includes Chrome, Edge, Firefox, and Opera.

## Classes

### SidebarError

Custom error class thrown when an API method is not supported or fails.

## Methods

- [getSidebarOptions(tabId?)](#getSidebarOptions)
- [getSidebarBehavior()](#getSidebarBehavior)
- [getSidebarOptions(tabId?)](#getSidebarOptions) [Chromium]
- [getSidebarBehavior()](#getSidebarBehavior) [Chromium]
- [canOpenSidebar()](#canOpenSidebar)
- [canCloseSidebar()](#canCloseSidebar)
- [openSidebar(options)](#openSidebar)
- [setSidebarOptions(options?)](#setSidebarOptions)
- [setSidebarBehavior(behavior?)](#setSidebarBehavior)
- [closeSidebar(options)](#closeSidebar)
- [setSidebarOptions(options?)](#setSidebarOptions) [Chromium]
- [setSidebarBehavior(behavior?)](#setSidebarBehavior) [Chromium]
- [isOpenSidebar(windowId?)](#isOpenSidebar)
- [toggleSidebar()](#toggleSidebar) [Firefox]
- [setSidebarPath(path, tabId?)](#setSidebarPath)
- [getSidebarPath(tabId?)](#getSidebarPath)
- [setSidebarTitle(title, tabId?)](#setSidebarTitle) [Firefox, Opera]
Expand All @@ -33,23 +43,23 @@ A promise-based wrapper around Chrome's side panel (`chrome.sidePanel`, MV3) and

<a name="getSidebarOptions"></a>

### getSidebarOptions
### getSidebarOptions [Chromium]

```
getSidebarOptions(tabId?: number): Promise<chrome.sidePanel.PanelOptions>
```

Retrieves the side panel options (e.g., `path`) for the specified tab. Throws if the Side Panel API isn't supported. [MV3]
Retrieves the side panel options (e.g., `path`) for the specified tab. Throws if the Side Panel API isn't supported (requires Chromium-based browsers like Chrome, Edge, or Opera MV3). [MV3]

<a name="getSidebarBehavior"></a>

### getSidebarBehavior
### getSidebarBehavior [Chromium]

```
getSidebarBehavior(): Promise<chrome.sidePanel.PanelBehavior>
```

Gets the current side panel behavior settings. Throws if unsupported. [MV3]
Gets the current side panel behavior settings. Throws if unsupported (requires Chromium-based browsers like Chrome, Edge, or Opera MV3). [MV3]

<a name="canOpenSidebar"></a>

Expand All @@ -59,7 +69,17 @@ Gets the current side panel behavior settings. Throws if unsupported. [MV3]
canOpenSidebar(): boolean
```

Returns `true` if `chrome.sidePanel` (MV3) is available, or if `browser.sidebarAction.open` is available (Firefox).
Returns `true` if `chrome.sidePanel` (Chromium MV3) is available, or if `sidebarAction.open` is available (Firefox/Opera).

<a name="canCloseSidebar"></a>

### canCloseSidebar

```
canCloseSidebar(): boolean
```

Returns `true` if `chrome.sidePanel` (Chromium MV3) is available, or if `sidebarAction.close` is available (Firefox/Opera).

<a name="openSidebar"></a>

Expand All @@ -69,27 +89,37 @@ Returns `true` if `chrome.sidePanel` (MV3) is available, or if `browser.sidebarA
openSidebar(options: chrome.sidePanel.OpenOptions): Promise<void>
```

Opens the side panel with the given options in Chrome (MV3). Falls back to `browser.sidebarAction.open()` in Firefox. Logs a warning and resolves as a no-op if unsupported.
Opens the side panel with the given options in Chromium-based browsers (MV3). Falls back to `sidebarAction.open()` in Firefox/Opera. Throws if unsupported.

<a name="closeSidebar"></a>

### closeSidebar

```
closeSidebar(options: chrome.sidePanel.CloseOptions): Promise<void>
```

Closes the side panel with the given options in Chromium-based browsers (MV3). Falls back to `sidebarAction.close()` in Firefox/Opera. Throws if unsupported.

<a name="setSidebarOptions"></a>

### setSidebarOptions
### setSidebarOptions [Chromium]

```
setSidebarOptions(options?: chrome.sidePanel.PanelOptions): Promise<void>
```

Sets side panel options (e.g., `path`) in Chrome (MV3). Logs a warning and resolves as a no-op if unsupported. [MV3]
Sets side panel options (e.g., `path`) in Chromium-based browsers (MV3). Throws if unsupported. [MV3]

<a name="setSidebarBehavior"></a>

### setSidebarBehavior
### setSidebarBehavior [Chromium]

```
setSidebarBehavior(behavior?: chrome.sidePanel.PanelBehavior): Promise<void>
```

Updates default panel behavior in Chrome (MV3). Logs a warning and resolves as a no-op if unsupported. [MV3]
Updates default panel behavior in Chromium-based browsers (MV3). Throws if unsupported. [MV3]

<a name="setSidebarPath"></a>

Expand All @@ -99,7 +129,7 @@ Updates default panel behavior in Chrome (MV3). Logs a warning and resolves as a
setSidebarPath(path: string, tabId?: number): Promise<void>
```

Sets the sidebar path in Chrome via `setOptions` (MV3) or via `sidebarAction.setPanel()` in Firefox/Opera. Throws if unsupported.
Sets the sidebar path in Chromium-based browsers via `setOptions` (MV3) or via `sidebarAction.setPanel()` in Firefox/Opera. Throws if unsupported.

<a name="getSidebarPath"></a>

Expand All @@ -109,7 +139,27 @@ Sets the sidebar path in Chrome via `setOptions` (MV3) or via `sidebarAction.set
getSidebarPath(tabId?: number): Promise<string | undefined>
```

Retrieves the sidebar path from Chrome (MV3) or parses from `sidebarAction.getPanel()` in Firefox/Opera. Throws if unsupported.
Retrieves the sidebar path from Chromium-based browsers (MV3) or parses from `sidebarAction.getPanel()` in Firefox/Opera. Throws if unsupported.

<a name="isOpenSidebar"></a>

### isOpenSidebar

```
isOpenSidebar(windowId?: number): Promise<boolean>
```

Checks if the sidebar is open for the given window in Chromium-based browsers (MV3) using `getContexts` and in Firefox/Opera using `sidebarAction.isOpen()`. Throws if unsupported.

<a name="toggleSidebar"></a>

### toggleSidebar [Firefox]

```
toggleSidebar(): Promise<void>
```

Toggles the sidebar in Firefox. Throws if unsupported.

<a name="setSidebarTitle"></a>

Expand All @@ -119,7 +169,7 @@ Retrieves the sidebar path from Chrome (MV3) or parses from `sidebarAction.getPa
setSidebarTitle(title: string | number, tabId?: number): Promise<void>
```

Sets the sidebar title via `sidebarAction.setTitle()` (Firefox/Opera). Logs a warning if unsupported.
Sets the sidebar title via `sidebarAction.setTitle()` (Firefox/Opera). Throws if unsupported.

<a name="setSidebarIcon"></a>

Expand All @@ -129,7 +179,7 @@ Sets the sidebar title via `sidebarAction.setTitle()` (Firefox/Opera). Logs a wa
setSidebarIcon(details: opr.sidebarAction.IconDetails): Promise<void>
```

Sets the sidebar icon via `sidebarAction.setIcon()` (Firefox/Opera). Logs a warning if unsupported.
Sets the sidebar icon via `sidebarAction.setIcon()` (Firefox/Opera). Throws if unsupported.

> Known issue (Opera): The `opr.sidebarAction.setIcon` API is currently broken and may fail with "Access to extension API denied".
> See: https://forums.opera.com/topic/75680/opr-sidebaraction-seticon-api-is-broken-access-to-extension-api-denied
Expand All @@ -142,7 +192,7 @@ Sets the sidebar icon via `sidebarAction.setIcon()` (Firefox/Opera). Logs a warn
setSidebarBadgeText(text: string | number, tabId?: number): Promise<void>
```

Sets the sidebar badge text via `opr.sidebarAction.setBadgeText()` (Opera only). Logs a warning if unsupported.
Sets the sidebar badge text via `opr.sidebarAction.setBadgeText()` (Opera only). Throws if unsupported.

<a name="clearSidebarBadgeText"></a>

Expand All @@ -162,7 +212,7 @@ Clears the sidebar badge text (equivalent to setting an empty string) via `opr.s
setSidebarBadgeTextColor(color: string | [number, number, number, number], tabId?: number): Promise<void>
```

Sets the sidebar badge text color via `opr.sidebarAction.setBadgeTextColor()` (Opera only). Logs a warning if unsupported.
Sets the sidebar badge text color via `opr.sidebarAction.setBadgeTextColor()` (Opera only). Throws if unsupported.

<a name="setSidebarBadgeBgColor"></a>

Expand All @@ -172,7 +222,7 @@ Sets the sidebar badge text color via `opr.sidebarAction.setBadgeTextColor()` (O
setSidebarBadgeBgColor(color: string | [number, number, number, number], tabId?: number): Promise<void>
```

Sets the sidebar badge background color via `opr.sidebarAction.setBadgeBackgroundColor()` (Opera only). Logs a warning if unsupported.
Sets the sidebar badge background color via `opr.sidebarAction.setBadgeBackgroundColor()` (Opera only). Throws if unsupported.

<a name="getSidebarTitle"></a>

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@commitlint/cli": "^20.0.0",
"@commitlint/config-conventional": "^20.0.0",
"@release-it/conventional-changelog": "^10.0.1",
"@types/chrome": "^0.1.12",
"@types/chrome": "^0.1.36",
"@types/jest": "^30.0.0",
"husky": "^9.1.7",
"jest": "^30.1.3",
Expand Down
Loading