-
-
Notifications
You must be signed in to change notification settings - Fork 424
Open
Labels
questionQuestions related to rodQuestions related to rod
Description
Rod Version: v0.116.2
The code to demonstrate your question
package main
import (
"log"
"os"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
)
func main() {
// Launch browser in non-headless mode
url := launcher.New().Headless(false).MustLaunch()
browser := rod.New().ControlURL(url).MustConnect()
defer browser.MustClose()
page1 := browser.MustPage("about:blank")
page2 := browser.MustPage("about:blank") // multiple tabs
pages := []*rod.Page{page1, page2}
page := pages[0]
page.MustNavigate("https://google.com").MustWaitLoad()
// Confirm page is loaded (DOM snapshot works fine)
log.Println("DOM snapshot captured")
// This call hangs indefinitely unless page1.MustActivate() is used before
screenshot, err := page.Screenshot(false, nil)
if err != nil {
log.Fatalf("Failed to take screenshot: %v", err)
}
// Save screenshot to file
err = os.WriteFile("screenshot.png", screenshot, 0644)
if err != nil {
log.Fatalf("Failed to save screenshot: %v", err)
}
log.Println("✅ Screenshot saved to screenshot.png")
}What you got
Calling .Screenshot() on a non-active page (i.e., not the most recently opened tab) causes the call to hang indefinitely - even in headless mode.
What you expect to see
Screenshot should be captured successfully regardless of whether the page is focused or not — similar to Puppeteer or Playwright behavior.
What have you tried to solve the question
- Verified that
page1.MustCaptureDOMSnapshot()works correctly -- proves the page is rendered. - Added
page1.MustActivate()before.Screenshot()-- fixes the issue. - Tried
MustScrollIntoView()-- had no effect - Happens consistently in both headless and non-headless modes
- Implemented serialization + manual focus workaround, but behavior is surprising
Metadata
Metadata
Assignees
Labels
questionQuestions related to rodQuestions related to rod