-
-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-32000 Not attached to an active page panic when ERR_CONNECTION_REFUSED #700
Comments
Please fix the format of your markdown: 3 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## Issue"]
25 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Below] [Context: "## What you got"]
26 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
26 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
38 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
39:9 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
39 MD022/blanks-around-headings/blanks-around-headers Headings should be surrounded by blank lines [Expected: 1; Actual: 0; Above] [Context: "## Issue"]
39 MD024/no-duplicate-heading/no-duplicate-header Multiple headings with the same content [Context: "## Issue"] generated by check-issue |
Rod will automatically close the page if the navigation fails, please read the source code of Lines 188 to 193 in 67a64b6
Your code won't execute the line of |
I can't reproduce your issue, the page is automatically closed with your code, it works fine to me. If you run it in headful mode, you should see a page show up and close quickly, watch it carefully. |
Ok, I thought the issue is with the standard Page load, it happens with Stealth though. Please check if this close the page for you func main() {
u := launcher.New().Headless(false).MustLaunch()
b := rod.New().ControlURL(u).MustConnect()
url := "http://localhost"
//p := b.MustPage(url)
p := stealth.MustPage(b)
defer p.Close()
err := rod.Try(func() { //Wait Max 15 Sec
p = p.Timeout(15 * time.Second).
MustNavigate(url).
CancelTimeout()
})
if err != nil {
//fmt.Println(err.Error())
}
for {
//Do nothing
}
} |
Works fine to me, try the code below, you have to wait for the wrong navigation is settled: package main
import (
"fmt"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/defaults"
"github.com/go-rod/rod/lib/utils"
"github.com/go-rod/stealth"
)
func main() {
defaults.Show = true
b := rod.New().MustConnect()
p := stealth.MustPage(b)
rod.Try(func() {
p.MustNavigate("http://localhost")
})
p.MustWaitNavigation() // watch out for this line
p.MustClose()
fmt.Println("page closed")
utils.Pause()
} I think this is a bug of chromium, it doesn't allow us to close a page while it's navigating. |
Why you don't see the error is because your code is not checking the error of Please always check errors returned by functions, or use |
Yes, that is the issue, if you want to control the time used to load the page using the timeout and modify the block err := rod.Try(func() { //Wait Max 15 Sec
p = p.Timeout(15 * time.Second).
MustNavigate(URL).
MustWaitNavigation(). //Notice here in the timeout block, it will not work
CancelTimeout()
}) But if moved outside the above block, it will work as in your example, but I will have to wait for the Page to Load, which can be time-consuming for some websites. |
About your last code, I think you should learn more about how panic works in golang. It's not related to rod. Use the lastest version of rod, it should work now. |
Rod Version: v0.107.3
Issue
try to navigate to any site that will trigger ERR_CONNECTION_REFUSED, then defer page close, the panic will happen.
Sample code
What you got
Issue
The reference to the opened page should be retained, so it can be closed properly, also as a precaution, the
MustClose()
method should check that the page is not nil.The text was updated successfully, but these errors were encountered: