@@ -269,7 +269,7 @@ export class RuntimeService {
269269
270270 if ( registerControl ?. userscripts_register_control !== USERSCRIPTS_REGISTER_CONTROL ) {
271271 await Promise . allSettled ( [
272- chrome . userScripts . unregister ( ) ,
272+ chrome . userScripts ? .unregister ( ) ,
273273 chrome . scripting . unregisterContentScripts ( ) ,
274274 chrome . storage . local . set ( { userscripts_register_control : USERSCRIPTS_REGISTER_CONTROL } ) ,
275275 ] ) ;
@@ -333,8 +333,8 @@ export class RuntimeService {
333333
334334 let registered = false ;
335335 try {
336- const res = await chrome . userScripts . getScripts ( { ids : [ "scriptcat-content" , "scriptcat-inject" ] } ) ;
337- registered = res . length === 2 ;
336+ const res = await chrome . userScripts ? .getScripts ( { ids : [ "scriptcat-content" , "scriptcat-inject" ] } ) ;
337+ registered = res ? .length === 2 ;
338338 } finally {
339339 // 考虑 UserScripts API 不可使用等情况
340340 runtimeGlobal . registered = registered ;
@@ -635,7 +635,7 @@ export class RuntimeService {
635635 // 即使注册失败,通过重置 flag 可避免错误地呼叫已取消注册的Script
636636 runtimeGlobal . messageFlag = this . generateMessageFlag ( ) ;
637637 await Promise . allSettled ( [
638- chrome . userScripts . unregister ( ) ,
638+ chrome . userScripts ? .unregister ( ) ,
639639 this . localStorageDAO . save ( { key : "scriptInjectMessageFlag" , value : runtimeGlobal . messageFlag } ) ,
640640 ] ) ;
641641 }
@@ -1361,7 +1361,8 @@ export class RuntimeService {
13611361 if ( forced ? false : ! this . isUserScriptsAvailable || ! this . isLoadScripts ) {
13621362 return ;
13631363 }
1364- const result = await chrome . userScripts . getScripts ( { ids : uuids } ) ;
1364+ const result = await chrome . userScripts ?. getScripts ( { ids : uuids } ) ;
1365+ if ( ! result ) return ; // 没 userScripts API 权限
13651366 const filteredIds = result . map ( ( entry ) => entry . id ) . filter ( ( id ) => ! ! id ) ;
13661367 if ( filteredIds . length > 0 ) {
13671368 // 修改脚本状态为disable,浏览器取消注册该脚本
0 commit comments