File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -472,13 +472,15 @@ export default class GMApi {
472
472
if ( options . useOpen === true ) {
473
473
const newWindow = window . open ( url ) ;
474
474
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
+ } ) ;
480
481
} else {
481
482
// 当新tab被浏览器阻止时window.open()会返回null 视为已经关闭
483
+ // 似乎在Firefox中禁止在background页面使用window.open(),强制返回null
482
484
channel . send ( { event : "onclose" } ) ;
483
485
channel . disChannel ( ) ;
484
486
}
Original file line number Diff line number Diff line change @@ -327,7 +327,7 @@ declare namespace GMTypes {
327
327
active ?: boolean ;
328
328
insert ?: boolean ;
329
329
setParent ?: boolean ;
330
- useOpen ?: boolean ;
330
+ useOpen ?: boolean ; // 这是一个实验性/不兼容其他管理器/不兼容Firefox的功能
331
331
}
332
332
333
333
interface XHRResponse {
You can’t perform that action at this time.
0 commit comments