File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -472,13 +472,15 @@ export default class GMApi {
472472 if ( options . useOpen === true ) {
473473 const newWindow = window . open ( url ) ;
474474 if ( newWindow ) {
475- // 使用onunload监听新tab关闭
476- newWindow . window . onunload = ( ) => {
477- channel . send ( { event : "onclose" } ) ;
478- channel . disChannel ( ) ;
479- } ;
475+ // 由于不符合同源策略无法直接监听newWindow关闭事件,因此改用CDP方法监听
476+ // 由于window.open强制在前台打开标签,因此获取状态为{ active:true }的标签即为新标签
477+ chrome . tabs . query ( { active : true } , ( [ tab ] ) => {
478+ Cache . getInstance ( ) . set ( `GM_openInTab:${ tab . id } ` , channel ) ;
479+ channel . send ( { event : "oncreate" , tabId : tab . id } ) ;
480+ } ) ;
480481 } else {
481482 // 当新tab被浏览器阻止时window.open()会返回null 视为已经关闭
483+ // 似乎在Firefox中禁止在background页面使用window.open(),强制返回null
482484 channel . send ( { event : "onclose" } ) ;
483485 channel . disChannel ( ) ;
484486 }
Original file line number Diff line number Diff line change @@ -327,7 +327,7 @@ declare namespace GMTypes {
327327 active ?: boolean ;
328328 insert ?: boolean ;
329329 setParent ?: boolean ;
330- useOpen ?: boolean ;
330+ useOpen ?: boolean ; // 这是一个实验性/不兼容其他管理器/不兼容Firefox的功能
331331 }
332332
333333 interface XHRResponse {
You can’t perform that action at this time.
0 commit comments