@@ -54,9 +54,8 @@ type Frame struct {
54
54
55
55
// A life cycle event is only considered triggered for a frame if the entire
56
56
// frame subtree has also had the life cycle event triggered.
57
- lifecycleEventsMu sync.RWMutex
58
- lifecycleEvents map [LifecycleEvent ]bool
59
- subtreeLifecycleEvents map [LifecycleEvent ]bool
57
+ lifecycleEventsMu sync.RWMutex
58
+ lifecycleEvents map [LifecycleEvent ]bool
60
59
61
60
documentHandle * ElementHandle
62
61
@@ -65,8 +64,6 @@ type Frame struct {
65
64
66
65
loadingStartedTime time.Time
67
66
68
- networkIdleCh chan struct {}
69
-
70
67
inflightRequestsMu sync.RWMutex
71
68
inflightRequests map [network.RequestID ]bool
72
69
@@ -94,21 +91,19 @@ func NewFrame(
94
91
}
95
92
96
93
return & Frame {
97
- BaseEventEmitter : NewBaseEventEmitter (ctx ),
98
- ctx : ctx ,
99
- page : m .page ,
100
- manager : m ,
101
- parentFrame : parentFrame ,
102
- childFrames : make (map [api.Frame ]bool ),
103
- id : frameID ,
104
- vu : k6ext .GetVU (ctx ),
105
- lifecycleEvents : make (map [LifecycleEvent ]bool ),
106
- subtreeLifecycleEvents : make (map [LifecycleEvent ]bool ),
107
- inflightRequests : make (map [network.RequestID ]bool ),
108
- executionContexts : make (map [executionWorld ]frameExecutionContext ),
109
- currentDocument : & DocumentInfo {},
110
- networkIdleCh : make (chan struct {}),
111
- log : log ,
94
+ BaseEventEmitter : NewBaseEventEmitter (ctx ),
95
+ ctx : ctx ,
96
+ page : m .page ,
97
+ manager : m ,
98
+ parentFrame : parentFrame ,
99
+ childFrames : make (map [api.Frame ]bool ),
100
+ id : frameID ,
101
+ vu : k6ext .GetVU (ctx ),
102
+ lifecycleEvents : make (map [LifecycleEvent ]bool ),
103
+ inflightRequests : make (map [network.RequestID ]bool ),
104
+ executionContexts : make (map [executionWorld ]frameExecutionContext ),
105
+ currentDocument : & DocumentInfo {},
106
+ log : log ,
112
107
}
113
108
}
114
109
@@ -168,8 +163,6 @@ func (f *Frame) clearLifecycle() {
168
163
f .lifecycleEvents = make (map [LifecycleEvent ]bool )
169
164
f .lifecycleEventsMu .Unlock ()
170
165
171
- f .page .frameManager .MainFrame ().recalculateLifecycle ()
172
-
173
166
// keep the request related to the document if present
174
167
// in f.inflightRequests
175
168
f .inflightRequestsMu .Lock ()
@@ -188,117 +181,11 @@ func (f *Frame) clearLifecycle() {
188
181
f .inflightRequests = inflightRequests
189
182
}
190
183
f .inflightRequestsMu .Unlock ()
191
-
192
- f .stopNetworkIdleTimer ()
193
- if f .inflightRequestsLen () == 0 {
194
- f .startNetworkIdleTimer ()
195
- }
196
- }
197
-
198
- func (f * Frame ) recalculateLifecycle () {
199
- f .log .Debugf ("Frame:recalculateLifecycle" , "fid:%s furl:%q" , f .ID (), f .URL ())
200
-
201
- // Start with triggered events.
202
- events := make (map [LifecycleEvent ]bool )
203
- f .lifecycleEventsMu .RLock ()
204
- {
205
- for k , v := range f .lifecycleEvents {
206
- events [k ] = v
207
- }
208
- }
209
- f .lifecycleEventsMu .RUnlock ()
210
-
211
- // Only consider a life cycle event as fired if it has triggered for all of subtree.
212
- f .childFramesMu .RLock ()
213
- {
214
- for child := range f .childFrames {
215
- cf := child .(* Frame )
216
- // a precaution for preventing a deadlock in *Frame.childFramesMu
217
- if cf == f {
218
- continue
219
- }
220
- cf .recalculateLifecycle ()
221
- for k := range events {
222
- if ! cf .hasSubtreeLifecycleEventFired (k ) {
223
- delete (events , k )
224
- }
225
- }
226
- }
227
- }
228
- f .childFramesMu .RUnlock ()
229
-
230
- // Check if any of the fired events should be considered fired when looking at the entire subtree.
231
- mainFrame := f .manager .MainFrame ()
232
- for k := range events {
233
- if f .hasSubtreeLifecycleEventFired (k ) {
234
- continue
235
- }
236
- f .emit (EventFrameAddLifecycle , k )
237
-
238
- if f != mainFrame {
239
- continue
240
- }
241
- switch k {
242
- case LifecycleEventLoad :
243
- f .page .emit (EventPageLoad , nil )
244
- case LifecycleEventDOMContentLoad :
245
- f .page .emit (EventPageDOMContentLoaded , nil )
246
- }
247
- }
248
-
249
- // Emit removal events
250
- f .lifecycleEventsMu .RLock ()
251
- {
252
- for k := range f .subtreeLifecycleEvents {
253
- if ok := events [k ]; ! ok {
254
- f .emit (EventFrameRemoveLifecycle , k )
255
- }
256
- }
257
- }
258
- f .lifecycleEventsMu .RUnlock ()
259
-
260
- f .lifecycleEventsMu .Lock ()
261
- {
262
- f .subtreeLifecycleEvents = make (map [LifecycleEvent ]bool )
263
- for k , v := range events {
264
- f .subtreeLifecycleEvents [k ] = v
265
- }
266
- }
267
- f .lifecycleEventsMu .Unlock ()
268
- }
269
-
270
- func (f * Frame ) stopNetworkIdleTimer () {
271
- f .log .Debugf ("Frame:stopNetworkIdleTimer" , "fid:%s furl:%q" , f .ID (), f .URL ())
272
-
273
- select {
274
- case f .networkIdleCh <- struct {}{}:
275
- default :
276
- }
277
- }
278
-
279
- func (f * Frame ) startNetworkIdleTimer () {
280
- f .log .Debugf ("Frame:startNetworkIdleTimer" , "fid:%s furl:%q" , f .ID (), f .URL ())
281
-
282
- if f .hasLifecycleEventFired (LifecycleEventNetworkIdle ) || f .IsDetached () {
283
- return
284
- }
285
-
286
- f .stopNetworkIdleTimer ()
287
-
288
- go func () {
289
- select {
290
- case <- f .ctx .Done ():
291
- case <- f .networkIdleCh :
292
- case <- time .After (LifeCycleNetworkIdleTimeout ):
293
- f .manager .frameLifecycleEvent (cdp .FrameID (f .ID ()), LifecycleEventNetworkIdle )
294
- }
295
- }()
296
184
}
297
185
298
186
func (f * Frame ) detach () {
299
187
f .log .Debugf ("Frame:detach" , "fid:%s furl:%q" , f .ID (), f .URL ())
300
188
301
- f .stopNetworkIdleTimer ()
302
189
f .setDetached (true )
303
190
if f .parentFrame != nil {
304
191
f .parentFrame .removeChildFrame (f )
@@ -416,13 +303,6 @@ func (f *Frame) hasLifecycleEventFired(event LifecycleEvent) bool {
416
303
return f .lifecycleEvents [event ]
417
304
}
418
305
419
- func (f * Frame ) hasSubtreeLifecycleEventFired (event LifecycleEvent ) bool {
420
- f .lifecycleEventsMu .RLock ()
421
- defer f .lifecycleEventsMu .RUnlock ()
422
-
423
- return f .subtreeLifecycleEvents [event ]
424
- }
425
-
426
306
func (f * Frame ) navigated (name string , url string , loaderID string ) {
427
307
f .log .Debugf ("Frame:navigated" , "fid:%s furl:%q lid:%s name:%q url:%q" , f .ID (), f .URL (), loaderID , name , url )
428
308
@@ -454,12 +334,10 @@ func (f *Frame) onLifecycleEvent(event LifecycleEvent) {
454
334
f .log .Debugf ("Frame:onLifecycleEvent" , "fid:%s furl:%q event:%s" , f .ID (), f .URL (), event )
455
335
456
336
f .lifecycleEventsMu .Lock ()
457
- defer f .lifecycleEventsMu .Unlock ()
458
-
459
- if ok := f .lifecycleEvents [event ]; ok {
460
- return
461
- }
462
337
f .lifecycleEvents [event ] = true
338
+ f .lifecycleEventsMu .Unlock ()
339
+
340
+ f .emit (EventFrameAddLifecycle , event )
463
341
}
464
342
465
343
func (f * Frame ) onLoadingStarted () {
@@ -478,9 +356,6 @@ func (f *Frame) onLoadingStopped() {
478
356
// requests so it may take a long time for us to see
479
357
// a networkIdle event or we may never see one if the
480
358
// website never stops performing network requests.
481
- // NOTE: This is a different timeout to networkIdleTimer,
482
- // which only works once there are no more network
483
- // requests and we don't see a networkIdle event.
484
359
}
485
360
486
361
func (f * Frame ) position () * Position {
@@ -1933,7 +1808,7 @@ func (f *Frame) WaitForNavigation(opts goja.Value) *goja.Promise {
1933
1808
// A lifecycle event won't be received when navigating within the same
1934
1809
// document, so don't wait for it. The event might've also already been
1935
1810
// fired once we're here, so also skip waiting in that case.
1936
- if ! sameDocNav && ! f .hasSubtreeLifecycleEventFired (parsedOpts .WaitUntil ) {
1811
+ if ! sameDocNav && ! f .hasLifecycleEventFired (parsedOpts .WaitUntil ) {
1937
1812
select {
1938
1813
case <- lifecycleEvtCh :
1939
1814
case <- timeoutCtx .Done ():
0 commit comments