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

how to hide pop window when using headless #1116

Open Q191 opened 6 days ago

Q191 commented 6 days ago

Rod Version: v0.116.2

The code to demonstrate your question

  1. Clone Rod to your local and cd to the repository:

    git clone https://github.com/go-rod/rod
    cd rod
  2. Use your code to replace the content of function TestRod in file rod_test.go.

  3. Test your code with: go test -run TestRod, make sure it fails as expected.

  4. Replace ALL THE CONTENT under "The code to demonstrate your question" with your TestRod function, like below:

const EDGE_BINARY_PATH = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"

func main() {
    l := launcher.New().Bin(EDGE_BINARY_PATH).Headless(true)
    lUrl := l.MustLaunch()
    browser := rod.New().ControlURL(lUrl).Trace(true).MustConnect()
    page := browser.MustPage("https://github.com/go-rod/rod")
    defer func() {
        page.Close()
        page.Browser().Close()
        l.Cleanup()
    }()
    time.Sleep(10 * time.Second)
}

What you got

a empty popup window

What you expect to see

no popup window

What have you tried to solve the question

try add

cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}

to all cmd, not work

github-actions[bot] commented 6 days ago

Please fix the format of your markdown:

46 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
46 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
48 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]

generated by check-issue

moxcomic commented 3 days ago

Did a white box pop up? I encountered this issue as well, but it only happens on Windows.

Q191 commented 3 hours ago

Did a white box pop up? I encountered this issue as well, but it only happens on Windows.

yes