File tree Expand file tree Collapse file tree 11 files changed +59
-15
lines changed Expand file tree Collapse file tree 11 files changed +59
-15
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import { helper } from './helper';
22
22
23
23
export interface BrowserContextDelegate {
24
24
pages ( ) : Promise < Page [ ] > ;
25
+ existingPages ( ) : Page [ ] ;
25
26
newPage ( ) : Promise < Page > ;
26
27
close ( ) : Promise < void > ;
27
28
@@ -69,6 +70,10 @@ export class BrowserContext {
69
70
await this . setGeolocation ( this . _options . geolocation ) ;
70
71
}
71
72
73
+ _existingPages ( ) : Page [ ] {
74
+ return this . _delegate . existingPages ( ) ;
75
+ }
76
+
72
77
async pages ( ) : Promise < Page [ ] > {
73
78
return this . _delegate . pages ( ) ;
74
79
}
Original file line number Diff line number Diff line change @@ -74,6 +74,15 @@ export class CRBrowser extends platform.EventEmitter implements Browser {
74
74
return pages . filter ( page => ! ! page ) as Page [ ] ;
75
75
} ,
76
76
77
+ existingPages : ( ) : Page [ ] => {
78
+ const pages : Page [ ] = [ ] ;
79
+ for ( const target of this . _allTargets ( ) ) {
80
+ if ( target . browserContext ( ) === context && target . _crPage )
81
+ pages . push ( target . _crPage . page ( ) ) ;
82
+ }
83
+ return pages ;
84
+ } ,
85
+
77
86
newPage : async ( ) : Promise < Page > => {
78
87
const { targetId } = await this . _client . send ( 'Target.createTarget' , { url : 'about:blank' , browserContextId : contextId || undefined } ) ;
79
88
const target = this . _targets . get ( targetId ) ! ;
Original file line number Diff line number Diff line change @@ -424,7 +424,7 @@ export class CRPage implements PageDelegate {
424
424
return this . _page . _frameManager . frame ( nodeInfo . node . frameId ) ;
425
425
}
426
426
427
- async getOwnerFrame ( handle : dom . ElementHandle ) : Promise < frames . Frame | null > {
427
+ async getOwnerFrame ( handle : dom . ElementHandle ) : Promise < string | null > {
428
428
// document.documentElement has frameId of the owner frame.
429
429
const documentElement = await handle . evaluateHandle ( node => {
430
430
const doc = node as Document ;
@@ -440,10 +440,10 @@ export class CRPage implements PageDelegate {
440
440
const nodeInfo = await this . _client . send ( 'DOM.describeNode' , {
441
441
objectId : remoteObject . objectId
442
442
} ) ;
443
- const frame = nodeInfo && typeof nodeInfo . node . frameId === 'string' ?
444
- this . _page . _frameManager . frame ( nodeInfo . node . frameId ) : null ;
443
+ const frameId = nodeInfo && typeof nodeInfo . node . frameId === 'string' ?
444
+ nodeInfo . node . frameId : null ;
445
445
await documentElement . dispose ( ) ;
446
- return frame ;
446
+ return frameId ;
447
447
}
448
448
449
449
isElementHandle ( remoteObject : any ) : boolean {
Original file line number Diff line number Diff line change @@ -135,7 +135,16 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
135
135
}
136
136
137
137
async ownerFrame ( ) : Promise < frames . Frame | null > {
138
- return this . _page . _delegate . getOwnerFrame ( this ) ;
138
+ const frameId = await this . _page . _delegate . getOwnerFrame ( this ) ;
139
+ if ( ! frameId )
140
+ return null ;
141
+ const pages = this . _page . browserContext ( ) . _existingPages ( ) ;
142
+ for ( const page of pages ) {
143
+ const frame = page . _frameManager . frame ( frameId ) ;
144
+ if ( frame )
145
+ return frame ;
146
+ }
147
+ return null ;
139
148
}
140
149
141
150
async contentFrame ( ) : Promise < frames . Frame | null > {
Original file line number Diff line number Diff line change @@ -164,6 +164,15 @@ export class FFBrowser extends platform.EventEmitter implements Browser {
164
164
return pages . filter ( page => ! ! page ) ;
165
165
} ,
166
166
167
+ existingPages : ( ) : Page [ ] => {
168
+ const pages : Page [ ] = [ ] ;
169
+ for ( const target of this . _allTargets ( ) ) {
170
+ if ( target . browserContext ( ) === context && target . _ffPage )
171
+ pages . push ( target . _ffPage . _page ) ;
172
+ }
173
+ return pages ;
174
+ } ,
175
+
167
176
newPage : async ( ) : Promise < Page > => {
168
177
const { targetId} = await this . _connection . send ( 'Target.newPage' , {
169
178
browserContextId : browserContextId || undefined
Original file line number Diff line number Diff line change @@ -373,14 +373,12 @@ export class FFPage implements PageDelegate {
373
373
return this . _page . _frameManager . frame ( contentFrameId ) ;
374
374
}
375
375
376
- async getOwnerFrame ( handle : dom . ElementHandle ) : Promise < frames . Frame | null > {
376
+ async getOwnerFrame ( handle : dom . ElementHandle ) : Promise < string | null > {
377
377
const { ownerFrameId } = await this . _session . send ( 'Page.describeNode' , {
378
378
frameId : handle . _context . frame . _id ,
379
379
objectId : toRemoteObject ( handle ) . objectId ! ,
380
380
} ) ;
381
- if ( ! ownerFrameId )
382
- return null ;
383
- return this . _page . _frameManager . frame ( ownerFrameId ) ;
381
+ return ownerFrameId || null ;
384
382
}
385
383
386
384
isElementHandle ( remoteObject : any ) : boolean {
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ export interface PageDelegate {
62
62
isElementHandle ( remoteObject : any ) : boolean ;
63
63
adoptElementHandle < T extends Node > ( handle : dom . ElementHandle < T > , to : dom . FrameExecutionContext ) : Promise < dom . ElementHandle < T > > ;
64
64
getContentFrame ( handle : dom . ElementHandle ) : Promise < frames . Frame | null > ; // Only called for frame owner elements.
65
- getOwnerFrame ( handle : dom . ElementHandle ) : Promise < frames . Frame | null > ;
65
+ getOwnerFrame ( handle : dom . ElementHandle ) : Promise < string | null > ; // Returns frameId.
66
66
getContentQuads ( handle : dom . ElementHandle ) : Promise < types . Quad [ ] | null > ;
67
67
layoutViewport ( ) : Promise < { width : number , height : number } > ;
68
68
setInputFiles ( handle : dom . ElementHandle < HTMLInputElement > , files : types . FilePayload [ ] ) : Promise < void > ;
Original file line number Diff line number Diff line change @@ -168,6 +168,18 @@ export class WKBrowser extends platform.EventEmitter implements Browser {
168
168
return await Promise . all ( pageProxies . map ( proxy => proxy . page ( ) ) ) ;
169
169
} ,
170
170
171
+ existingPages : ( ) : Page [ ] => {
172
+ const pages : Page [ ] = [ ] ;
173
+ for ( const pageProxy of this . _pageProxies . values ( ) ) {
174
+ if ( pageProxy . _browserContext !== context )
175
+ continue ;
176
+ const page = pageProxy . existingPage ( ) ;
177
+ if ( page )
178
+ pages . push ( page ) ;
179
+ }
180
+ return pages ;
181
+ } ,
182
+
171
183
newPage : async ( ) : Promise < Page > => {
172
184
const { pageProxyId } = await this . _browserSession . send ( 'Browser.createPage' , { browserContextId } ) ;
173
185
const pageProxy = this . _pageProxies . get ( pageProxyId ) ! ;
Original file line number Diff line number Diff line change @@ -484,16 +484,14 @@ export class WKPage implements PageDelegate {
484
484
return this . _page . _frameManager . frame ( nodeInfo . contentFrameId ) ;
485
485
}
486
486
487
- async getOwnerFrame ( handle : dom . ElementHandle ) : Promise < frames . Frame | null > {
487
+ async getOwnerFrame ( handle : dom . ElementHandle ) : Promise < string | null > {
488
488
const remoteObject = toRemoteObject ( handle ) ;
489
489
if ( ! remoteObject . objectId )
490
490
return null ;
491
491
const nodeInfo = await this . _session . send ( 'DOM.describeNode' , {
492
492
objectId : remoteObject . objectId
493
493
} ) ;
494
- if ( ! nodeInfo . ownerFrameId )
495
- return null ;
496
- return this . _page . _frameManager . frame ( nodeInfo . ownerFrameId ) ;
494
+ return nodeInfo . ownerFrameId || null ;
497
495
}
498
496
499
497
isElementHandle ( remoteObject : any ) : boolean {
Original file line number Diff line number Diff line change @@ -99,6 +99,10 @@ export class WKPageProxy {
99
99
return this . _pagePromise ;
100
100
}
101
101
102
+ existingPage ( ) : Page | undefined {
103
+ return this . _wkPage ? this . _wkPage . _page : undefined ;
104
+ }
105
+
102
106
onPopupCreated ( popupPageProxy : WKPageProxy ) {
103
107
const wkPage = this . _wkPage ;
104
108
if ( ! wkPage || ! wkPage . _page . listenerCount ( Events . Page . Popup ) )
You can’t perform that action at this time.
0 commit comments