go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.

Home Page:https://go-rod.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

failed page screenshot in defer

feeops opened this issue · comments

Rod Version: v0.116.0

The code to demonstrate your question

package main

import (
	"github.com/go-rod/rod"
	"time"
)

func main() {
	// 连接浏览器
	browser := rod.New().MustConnect().Timeout(10 * time.Second)

	defer browser.MustClose()

	// 打开网页
	page := browser.MustPage("https://www.baidu.com").MustWaitLoad()

	// 使用 defer 来确保在函数退出前执行截图操作
	defer page.MustScreenshot("demo.png")

	time.Sleep(15 * time.Second)

}

What you got

panic: context deadline exceeded

What you expect to see

Get demo.png file

What have you tried to solve the question

none

Please fix the format of your markdown:

45:5 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]

generated by check-issue

Ask chatgpt about your code, it will solve it

CleanShot 2024-06-03 at 17 34 28@2x