go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.
https://go-rod.github.io
MIT License
5.26k stars 345 forks source link

[BUG FIX REQUEST] About MustWaitRequestIdle #789

Open musicyin opened 1 year ago

musicyin commented 1 year ago

Rod Version: v0.112.3

How to reproduce the issue

Turn on the "trace" mode , Call page.MustWaitRequestIdle() in looping and make some click that go to other page.

Panic Information

panic: assignment to entry in nil map goroutine 9 [running]: github.com/go-rod/rod.(Page).setHelper(0x562156?, {0xc00001e390?, 0x53b580?}, {0x557d03, 0x9}, {0xc00001e3a8, 0x17}) C:/Users/Administrator/go/pkg/mod/github.com/go-rod/rod@v0.112.3/page_eval.go:321 +0x127 github.com/go-rod/rod.(Page).ensureJSHelper(0x0?, 0xae9900) C:/Users/Administrator/go/pkg/mod/github.com/go-rod/rod@v0.112.3/page_eval.go:263 +0x1b3 github.com/go-rod/rod.(Page).formatArgs(0x0?, 0x8?) C:/Users/Administrator/go/pkg/mod/github.com/go-rod/rod@v0.112.3/page_eval.go:233 +0x239 github.com/go-rod/rod.(Page).evaluate(0x1c9c380?, 0xc000a29ed0) C:/Users/Administrator/go/pkg/mod/github.com/go-rod/rod@v0.112.3/page_eval.go:149 +0x3b github.com/go-rod/rod.(Page).Evaluate(0xc0002c8000, 0xc000a29ed0) C:/Users/Administrator/go/pkg/mod/github.com/go-rod/rod@v0.112.3/page_eval.go:128 +0x4e github.com/go-rod/rod.(Page).Overlay.func1() C:/Users/Administrator/go/pkg/mod/github.com/go-rod/rod@v0.112.3/dev_helpers.go:127 +0x150 github.com/go-rod/rod.(Page).tryTraceReq.func3() C:/Users/Administrator/go/pkg/mod/github.com/go-rod/rod@v0.112.3/dev_helpers.go:185 +0x218 created by github.com/go-rod/rod.(Page).tryTraceReq C:/Users/Administrator/go/pkg/mod/github.com/go-rod/rod@v0.112.3/dev_helpers.go:178 +0x2b8

Solved after changing this

tryTraceReq function in dev_helpers.go

if len(waitList)>0 { p.browser.logger.Println(TraceTypeWaitRequests, p, waitList) }

setHelper function in page_eval.go

if p.helpers != nil && p.helpers[jsCtxID] != nil { p.helpers[jsCtxID][name] = fnID }

gopkg-dev commented 4 months ago

I've also encountered this bug. When I call page.MustWaitRequestIdle(), it results in a panic: assignment to entry in nil map.