@@ -117,10 +117,18 @@ func (m *FrameManager) frameAbortedNavigation(frameID cdp.FrameID, errorText, do
117
117
defer m .framesMu .Unlock ()
118
118
119
119
frame := m .frames [frameID ]
120
- if frame == nil || frame .pendingDocument == nil {
120
+ if frame == nil {
121
+ return
122
+ }
123
+
124
+ frame .pendingDocumentMu .Lock ()
125
+
126
+ if frame .pendingDocument == nil {
127
+ frame .pendingDocumentMu .Unlock ()
121
128
return
122
129
}
123
130
if documentID != "" && frame .pendingDocument .documentID != documentID {
131
+ frame .pendingDocumentMu .Unlock ()
124
132
return
125
133
}
126
134
@@ -135,6 +143,9 @@ func (m *FrameManager) frameAbortedNavigation(frameID cdp.FrameID, errorText, do
135
143
err : errors .New (errorText ),
136
144
}
137
145
frame .pendingDocument = nil
146
+
147
+ frame .pendingDocumentMu .Unlock ()
148
+
138
149
frame .emit (EventFrameNavigation , ne )
139
150
}
140
151
@@ -266,6 +277,9 @@ func (m *FrameManager) frameNavigated(frameID cdp.FrameID, parentFrameID cdp.Fra
266
277
267
278
frame .navigated (name , url , documentID )
268
279
280
+ frame .pendingDocumentMu .Lock ()
281
+ defer frame .pendingDocumentMu .Unlock ()
282
+
269
283
var (
270
284
keepPending * DocumentInfo
271
285
pendingDocument = frame .pendingDocument
@@ -362,6 +376,9 @@ func (m *FrameManager) frameRequestedNavigation(frameID cdp.FrameID, url string,
362
376
b .AddFrameNavigation (frame )
363
377
}
364
378
379
+ frame .pendingDocumentMu .Lock ()
380
+ defer frame .pendingDocumentMu .Unlock ()
381
+
365
382
if frame .pendingDocument != nil && frame .pendingDocument .documentID == documentID {
366
383
m .logger .Debugf ("FrameManager:frameRequestedNavigation:return" ,
367
384
"fmid:%d fid:%v furl:%s url:%s docid:%s pdocid:%s pdoc:dontSet" ,
@@ -433,29 +450,43 @@ func (m *FrameManager) requestFailed(req *Request, canceled bool) {
433
450
}
434
451
frame .deleteRequest (req .getID ())
435
452
436
- switch rc := frame .inflightRequestsLen (); {
453
+ ifr := frame .cloneInflightRequests ()
454
+ switch rc := len (ifr ); {
437
455
case rc == 0 :
438
456
frame .startNetworkIdleTimer ()
439
457
case rc <= 10 :
440
- for reqID := range frame . inflightRequests {
458
+ for reqID := range ifr {
441
459
req := frame .requestByID (reqID )
442
460
461
+ if req == nil {
462
+ m .logger .Debugf ("FrameManager:requestFailed:rc<=10 request is nil" ,
463
+ "reqID:%s frameID:%s" ,
464
+ reqID , frame .ID ())
465
+ continue
466
+ }
467
+
443
468
m .logger .Debugf ("FrameManager:requestFailed:rc<=10" ,
444
469
"reqID:%s inflightURL:%s frameID:%s" ,
445
470
reqID , req .URL (), frame .ID ())
446
471
}
447
472
}
448
473
474
+ frame .pendingDocumentMu .RLock ()
449
475
if frame .pendingDocument == nil || frame .pendingDocument .request != req {
450
476
m .logger .Debugf ("FrameManager:requestFailed:return" , "fmid:%d pdoc:nil" , m .ID ())
477
+ frame .pendingDocumentMu .RUnlock ()
451
478
return
452
479
}
480
+
453
481
errorText := req .errorText
454
482
if canceled {
455
483
errorText += "; maybe frame was detached?"
456
484
}
457
- m .frameAbortedNavigation (cdp .FrameID (frame .ID ()), errorText ,
458
- frame .pendingDocument .documentID )
485
+
486
+ docID := frame .pendingDocument .documentID
487
+ frame .pendingDocumentMu .RUnlock ()
488
+
489
+ m .frameAbortedNavigation (cdp .FrameID (frame .ID ()), errorText , docID )
459
490
}
460
491
461
492
func (m * FrameManager ) requestFinished (req * Request ) {
@@ -510,7 +541,9 @@ func (m *FrameManager) requestStarted(req *Request) {
510
541
frame .stopNetworkIdleTimer ()
511
542
}
512
543
if req .documentID != "" {
544
+ frame .pendingDocumentMu .Lock ()
513
545
frame .pendingDocument = & DocumentInfo {documentID : req .documentID , request : req }
546
+ frame .pendingDocumentMu .Unlock ()
514
547
}
515
548
m .logger .Debugf ("FrameManager:requestStarted" , "fmid:%d rurl:%s pdoc:nil" , m .ID (), req .URL ())
516
549
}
0 commit comments