@@ -2,6 +2,7 @@ import { IS_MV3 } from "@util/constant/environment"
22import { handleError } from "./common"
33
44export 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
2122export 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
3840export 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
4851export 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