chromedp / chromedp

A faster, simpler way to drive browsers supporting the Chrome DevTools Protocol.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unexpected performance impact on devtools console method

meltfar opened this issue · comments

What versions are you running?

$ go list -m github.com/chromedp/chromedp
github.com/chromedp/chromedp v0.9.5
$ google-chrome --version
Version 1.63.157 Chromium: 122.0.6261.43 (Official Build)  (64-bit)
$ go version
go version go1.20.4 windows/amd64

What did you do? Include clear steps.

        ctx, _ := chromedp.NewRemoteAllocator(context.Background(), "ws://127.0.0.1:9222")
	ctx, _ = chromedp.NewContext(ctx)

	if err := chromedp.Run(ctx,
		network.Enable(),
		log.Disable(),
		css.Disable(),
		inspector.Disable(),
		chromedp.Navigate("https://blog.aepkill.com/demos/devtools-detector/"),
		chromedp.Sleep(time.Second*3),
		chromedp.Evaluate(`const btn = document.createElement('button'); btn.textContent = "click me!"; btn.id = 'btn'; document.body.appendChild(btn); btn.onclick=function () {const v1 = document.createElement('div'); v1.textContent = 'v1'; document.body.appendChild(v1)}`, nil),
		chromedp.Sleep(time.Second*5),
		chromedp.Click("#btn", chromedp.ByQuery),
	); err != nil {
		panic(err)
	}

What did you expect to see?

Keeping devtools page closed, so that devtools shouldn't be detected. The page should shown as "Devtools: close".

What did you see instead?

Devtools can be detected as opened while actually not, especially when chromedp.Sleep running.
The page shows that Devtools Opens because of performance impact.

Description

I was very curious about this strange performance issue. By running the code above, the webpage shows the browser with devtools page opening, which was because it detected a performance impact on console.log, console.table or largeArrayCreation within its code. But that should not happen.

I have also check with a python port of cdp client, with the same behaviours as nivagating, sleeping, executing js code and finally click it by calling dispatchMouseEvent, it runs smoothly without any performance impact after multiple attempts.

And it seems that the performance impact may occurred during chromedp.Sleep(). I'm not 100% sure about this. But if I delete all sleeping invocation, there is a chance that the webpage cannot detect any performance issue.