Skip to content

Commit 06646a3

Browse files
authored
fix: undefined tabGroups for Firefox
1 parent 7db1273 commit 06646a3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/api/chrome/tabGroups.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { IS_MV3 } from "@util/constant/environment"
22
import { handleError } from "./common"
33

44
export async function listAllGroups(): Promise<chrome.tabGroups.TabGroup[]> {
5+
if (!chrome.tabGroups) return []
56
if (IS_MV3) {
67
try {
78
return chrome.tabGroups.query({})
@@ -20,6 +21,7 @@ export async function listAllGroups(): Promise<chrome.tabGroups.TabGroup[]> {
2021

2122
export async function getGroup(id: number | undefined): Promise<chrome.tabGroups.TabGroup | undefined> {
2223
if (!id) return undefined
24+
if (!chrome.tabGroups) return undefined
2325
try {
2426
if (IS_MV3) {
2527
const group = await chrome.tabGroups.get(id)
@@ -37,6 +39,7 @@ export async function getGroup(id: number | undefined): Promise<chrome.tabGroups
3739

3840
export function onChanged(handler: ArgCallback<chrome.tabGroups.TabGroup>): void {
3941
try {
42+
if (!chrome.tabGroups) return
4043
chrome.tabGroups.onCreated.addListener(handler)
4144
chrome.tabGroups.onRemoved.addListener(handler)
4245
chrome.tabGroups.onUpdated.addListener(handler)
@@ -47,6 +50,7 @@ export function onChanged(handler: ArgCallback<chrome.tabGroups.TabGroup>): void
4750

4851
export function removeChangedHandler(handler: ArgCallback<chrome.tabGroups.TabGroup>): void {
4952
try {
53+
if (!chrome.tabGroups) return
5054
chrome.tabGroups.onCreated.removeListener(handler)
5155
chrome.tabGroups.onRemoved.removeListener(handler)
5256
chrome.tabGroups.onUpdated.removeListener(handler)
@@ -77,4 +81,4 @@ export const cvtGroupColor = (color?: `${chrome.tabGroups.Color}`): string => {
7781
case 'orange': return '#FA913E'
7882
default: return '#000'
7983
}
80-
}
84+
}

0 commit comments

Comments
 (0)