@@ -32,6 +32,7 @@ export class WKPageProxy {
32
32
private _wkPage : WKPage | null = null ;
33
33
private readonly _firstTargetPromise : Promise < void > ;
34
34
private _firstTargetCallback ?: ( ) => void ;
35
+ private _pagePausedOnStart : boolean = false ;
35
36
private readonly _sessions = new Map < string , WKSession > ( ) ;
36
37
private readonly _eventListeners : RegisteredListener [ ] ;
37
38
@@ -121,7 +122,11 @@ export class WKPageProxy {
121
122
}
122
123
assert ( session , 'One non-provisional target session must exist' ) ;
123
124
this . _wkPage = new WKPage ( this . _browserContext , this . _pageProxySession ) ;
124
- await this . _wkPage . initialize ( session ! ) ;
125
+ await this . _wkPage . initialize ( session ! , this . _pagePausedOnStart ) ;
126
+ if ( this . _pagePausedOnStart ) {
127
+ this . _resumeTarget ( session ! . sessionId ) ;
128
+ this . _pagePausedOnStart = false ;
129
+ }
125
130
return this . _wkPage . _page ;
126
131
}
127
132
@@ -140,19 +145,26 @@ export class WKPageProxy {
140
145
this . _firstTargetCallback ( ) ;
141
146
this . _firstTargetCallback = undefined ;
142
147
}
143
- if ( targetInfo . isProvisional )
148
+ if ( targetInfo . isProvisional ) {
144
149
( session as any ) [ isPovisionalSymbol ] = true ;
145
- if ( targetInfo . isProvisional && this . _wkPage )
146
- this . _wkPage . onProvisionalLoadStarted ( session ) ;
147
- if ( targetInfo . isPaused ) {
148
- const resume = ( ) => this . _pageProxySession . send ( 'Target.resume' , { targetId : targetInfo . targetId } ) . catch ( debugError ) ;
149
- if ( targetInfo . isProvisional || ! this . _pagePromise )
150
- resume ( ) ;
151
- else
152
- this . _pagePromise . then ( resume ) ;
150
+ if ( this . _wkPage )
151
+ this . _wkPage . onProvisionalLoadStarted ( session ) ;
152
+ if ( targetInfo . isPaused )
153
+ this . _resumeTarget ( targetInfo . targetId ) ;
154
+ } else if ( this . _pagePromise ) {
155
+ assert ( ! this . _pagePausedOnStart ) ;
156
+ // This is the first time page target is created, will resume
157
+ // after finishing intialization.
158
+ this . _pagePausedOnStart = ! ! targetInfo . isPaused ;
159
+ } else if ( targetInfo . isPaused ) {
160
+ this . _resumeTarget ( targetInfo . targetId ) ;
153
161
}
154
162
}
155
163
164
+ private _resumeTarget ( targetId : string ) {
165
+ this . _pageProxySession . send ( 'Target.resume' , { targetId } ) . catch ( debugError ) ;
166
+ }
167
+
156
168
private _onTargetDestroyed ( event : Protocol . Target . targetDestroyedPayload ) {
157
169
const { targetId, crashed } = event ;
158
170
const session = this . _sessions . get ( targetId ) ;
0 commit comments