Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit b2011d0

Browse files
committed
Remove neworkidle timer as its not needed
This timer is no longer needed since the fixes in PR #555 and #597. These PRs helped to ensure that we receive the CDP events in order and that we correctly handle them when we do receive them. The networkidle timer was in place for a situation where we might not receive the networkidle lifecycle event from the browser via CDP. This could still occur, which would mean that there's a bug outside of our direct control. When this happens we should find a better solution.
1 parent 215000d commit b2011d0

File tree

2 files changed

+0
-51
lines changed

2 files changed

+0
-51
lines changed

common/frame.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ type Frame struct {
6565

6666
loadingStartedTime time.Time
6767

68-
networkIdleCh chan struct{}
69-
7068
inflightRequestsMu sync.RWMutex
7169
inflightRequests map[network.RequestID]bool
7270

@@ -107,7 +105,6 @@ func NewFrame(
107105
inflightRequests: make(map[network.RequestID]bool),
108106
executionContexts: make(map[executionWorld]frameExecutionContext),
109107
currentDocument: &DocumentInfo{},
110-
networkIdleCh: make(chan struct{}),
111108
log: log,
112109
}
113110
}
@@ -188,11 +185,6 @@ func (f *Frame) clearLifecycle() {
188185
f.inflightRequests = inflightRequests
189186
}
190187
f.inflightRequestsMu.Unlock()
191-
192-
f.stopNetworkIdleTimer()
193-
if f.inflightRequestsLen() == 0 {
194-
f.startNetworkIdleTimer()
195-
}
196188
}
197189

198190
func (f *Frame) recalculateLifecycle() {
@@ -267,38 +259,9 @@ func (f *Frame) recalculateLifecycle() {
267259
f.lifecycleEventsMu.Unlock()
268260
}
269261

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-
}
297-
298262
func (f *Frame) detach() {
299263
f.log.Debugf("Frame:detach", "fid:%s furl:%q", f.ID(), f.URL())
300264

301-
f.stopNetworkIdleTimer()
302265
f.setDetached(true)
303266
if f.parentFrame != nil {
304267
f.parentFrame.removeChildFrame(f)

common/frame_manager.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ func (m *FrameManager) removeBarrier(b *Barrier) {
100100

101101
func (m *FrameManager) dispose() {
102102
m.logger.Debugf("FrameManager:dispose", "fmid:%d", m.ID())
103-
104-
m.framesMu.RLock()
105-
defer m.framesMu.RUnlock()
106-
for _, f := range m.frames {
107-
f.stopNetworkIdleTimer()
108-
}
109103
}
110104

111105
func (m *FrameManager) frameAbortedNavigation(frameID cdp.FrameID, errorText, documentID string) {
@@ -452,8 +446,6 @@ func (m *FrameManager) requestFailed(req *Request, canceled bool) {
452446

453447
ifr := frame.cloneInflightRequests()
454448
switch rc := len(ifr); {
455-
case rc == 0:
456-
frame.startNetworkIdleTimer()
457449
case rc <= 10:
458450
for reqID := range ifr {
459451
req := frame.requestByID(reqID)
@@ -503,9 +495,6 @@ func (m *FrameManager) requestFinished(req *Request) {
503495
return
504496
}
505497
frame.deleteRequest(req.getID())
506-
if frame.inflightRequestsLen() == 0 {
507-
frame.startNetworkIdleTimer()
508-
}
509498
/*
510499
else if frame.inflightRequestsLen() <= 10 {
511500
for reqID, _ := range frame.inflightRequests {
@@ -537,9 +526,6 @@ func (m *FrameManager) requestStarted(req *Request) {
537526
}
538527

539528
frame.addRequest(req.getID())
540-
if frame.inflightRequestsLen() == 1 {
541-
frame.stopNetworkIdleTimer()
542-
}
543529
if req.documentID != "" {
544530
frame.pendingDocumentMu.Lock()
545531
frame.pendingDocument = &DocumentInfo{documentID: req.documentID, request: req}

0 commit comments

Comments
 (0)