@@ -267,6 +267,7 @@ export default class GMApi extends GM_Base {
267267 }
268268
269269 static _GM_setValue ( a : GMApi , promise : any , key : string , value : any ) {
270+ key = `${ key } ` ;
270271 if ( ! a . scriptRes ) return ;
271272 if ( valChangeCounterId > 1e8 ) {
272273 // 防止 valChangeCounterId 过大导致无法正常工作
@@ -498,7 +499,7 @@ export default class GMApi extends GM_Base {
498499 if ( typeof message !== "string" ) {
499500 message = Native . jsonStringify ( message ) ;
500501 }
501- this . sendMessage ( "GM_log" , [ message , level , labels ] ) ;
502+ this . sendMessage ( "GM_log" , [ ` ${ message } ` , ` ${ level } ` , labels ] ) ;
502503 }
503504
504505 @GMContext . API ( { depend : [ "GM_log" ] } )
@@ -521,7 +522,7 @@ export default class GMApi extends GM_Base {
521522 // 辅助GM_xml获取blob数据
522523 @GMContext . API ( )
523524 public CAT_fetchBlob ( url : string ) : Promise < Blob > {
524- return this . sendMessage ( "CAT_fetchBlob" , [ url ] ) ;
525+ return this . sendMessage ( "CAT_fetchBlob" , [ ` ${ url } ` ] ) ;
525526 }
526527
527528 @GMContext . API ( )
@@ -540,17 +541,25 @@ export default class GMApi extends GM_Base {
540541 details : GMTypes . CookieDetails ,
541542 done : ( cookie : GMTypes . Cookie [ ] | any , error : any | undefined ) => void
542543 ) {
543- // 如果url和域名都没有,自动填充当前url
544- if ( ! details . url && ! details . domain ) {
545- details . url = window . location . href ;
546- }
547- // 如果是set、delete操作,自动填充当前url
548- if ( action === "set" || action === "delete" ) {
549- if ( ! details . url ) {
550- details . url = window . location . href ;
551- }
544+ // 防止错误参数类型传送
545+ if (
546+ typeof ( details || false ) !== "object" ||
547+ typeof ( details . domain ?? "" ) !== "string" ||
548+ typeof ( details . expirationDate ?? 0 ) !== "number" ||
549+ typeof ( details . httpOnly ?? false ) !== "boolean" ||
550+ typeof ( details . name ?? "" ) !== "string" ||
551+ typeof ( details . partitionKey ?? null ) !== "object" ||
552+ typeof ( details . path ?? "" ) !== "string" ||
553+ typeof ( details . secure ?? false ) !== "boolean" ||
554+ typeof ( details . session ?? false ) !== "boolean" ||
555+ typeof ( details . url ?? "" ) !== "string" ||
556+ typeof ( details . value ?? "" ) !== "string"
557+ ) {
558+ done ( undefined , new Error ( "Invalid Argument Type" ) ) ;
559+ return ;
552560 }
553- a . sendMessage ( "GM_cookie" , [ action , details ] )
561+ // 确保物件参数可以传送
562+ a . sendMessage ( "GM_cookie" , [ `${ action } ` , customClone ( details ) ] )
554563 . then ( ( resp : any ) => {
555564 done && done ( resp , undefined ) ;
556565 } )
@@ -707,7 +716,7 @@ export default class GMApi extends GM_Base {
707716 this . EE . addListener ( "menuClick:" + menuKey , listener ) ;
708717 }
709718 // 发送至 service worker 处理(唯一键,显示名字,不包括id的其他设定)
710- this . sendMessage ( "GM_registerMenuCommand" , [ menuKey , name , options ] as GMRegisterMenuCommandParam ) ;
719+ this . sendMessage ( "GM_registerMenuCommand" , [ menuKey , ` ${ name } ` , options ] as GMRegisterMenuCommandParam ) ;
711720 return ret ;
712721 }
713722
@@ -889,27 +898,29 @@ export default class GMApi extends GM_Base {
889898 const url = await toBlobURL ( this , details . data ) ;
890899 sendDetails . data = url ;
891900 }
892- this . sendMessage ( "CAT_fileStorage" , [ action , sendDetails ] ) . then ( async ( resp : { action : string ; data : any } ) => {
893- switch ( resp . action ) {
894- case "onload" : {
895- if ( action === "download" ) {
896- // 读取blob
897- const blob = await this . CAT_fetchBlob ( resp . data ) ;
898- details . onload && details . onload ( blob ) ;
899- } else {
900- details . onload && details . onload ( resp . data ) ;
901+ this . sendMessage ( "CAT_fileStorage" , [ `${ action } ` , sendDetails ] ) . then (
902+ async ( resp : { action : string ; data : any } ) => {
903+ switch ( resp . action ) {
904+ case "onload" : {
905+ if ( action === "download" ) {
906+ // 读取blob
907+ const blob = await this . CAT_fetchBlob ( resp . data ) ;
908+ details . onload && details . onload ( blob ) ;
909+ } else {
910+ details . onload && details . onload ( resp . data ) ;
911+ }
912+ break ;
901913 }
902- break ;
903- }
904- case "error" : {
905- if ( typeof resp . data . code === "undefined" ) {
906- details . onerror && details . onerror ( { code : - 1 , message : resp . data . message } ) ;
907- return ;
914+ case "error" : {
915+ if ( typeof resp . data . code === "undefined" ) {
916+ details . onerror && details . onerror ( { code : - 1 , message : resp . data . message } ) ;
917+ return ;
918+ }
919+ details . onerror && details . onerror ( resp . data ) ;
908920 }
909- details . onerror && details . onerror ( resp . data ) ;
910921 }
911922 }
912- } ) ;
923+ ) ;
913924 }
914925
915926 // 用于脚本跨域请求,需要@connect domain指定允许的域名
@@ -1199,7 +1210,7 @@ export default class GMApi extends GM_Base {
11991210 if ( typeof data . tag === "string" ) {
12001211 notificationId = notificationTagMap . get ( data . tag ) ;
12011212 }
1202- gmApi . sendMessage ( "GM_notification" , [ data , notificationId ] ) . then ( ( id ) => {
1213+ gmApi . sendMessage ( "GM_notification" , [ customClone ( data ) , notificationId ] ) . then ( ( id ) => {
12031214 if ( ! gmApi . EE ) return ;
12041215 if ( create ) {
12051216 create . apply ( { id } , [ id ] ) ;
@@ -1292,13 +1303,13 @@ export default class GMApi extends GM_Base {
12921303 // ScriptCat 额外API
12931304 @GMContext . API ( { alias : "GM.closeNotification" } )
12941305 public GM_closeNotification ( id : string ) : void {
1295- this . sendMessage ( "GM_closeNotification" , [ id ] ) ;
1306+ this . sendMessage ( "GM_closeNotification" , [ ` ${ id } ` ] ) ;
12961307 }
12971308
12981309 // ScriptCat 额外API
12991310 @GMContext . API ( { alias : "GM.updateNotification" } )
13001311 public GM_updateNotification ( id : string , details : GMTypes . NotificationDetails ) : void {
1301- this . sendMessage ( "GM_updateNotification" , [ id , details ] ) ;
1312+ this . sendMessage ( "GM_updateNotification" , [ ` ${ id } ` , customClone ( details ) ] ) ;
13021313 }
13031314
13041315 @GMContext . API ( { depend : [ "GM_closeInTab" ] } )
@@ -1439,7 +1450,7 @@ export default class GMApi extends GM_Base {
14391450 // 参考: https://github.com/Tampermonkey/tampermonkey/issues/1250
14401451 let mimetype : string | undefined ;
14411452 if ( typeof info === "object" && info ?. mimetype ) {
1442- mimetype = info . mimetype ;
1453+ mimetype = ` ${ info . mimetype } ` ;
14431454 } else {
14441455 mimetype = ( typeof info === "string" ? info : info ?. type ) || "text/plain" ;
14451456 if ( mimetype === "text" ) mimetype = "text/plain" ;
0 commit comments