go-rod / rod

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

failed page screenshot in defer #1068

Closed feeops closed 3 weeks ago

feeops commented 3 weeks ago

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

github-actions[bot] commented 3 weeks ago

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

ysmood commented 3 weeks ago

Ask chatgpt about your code, it will solve it

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