Open ryooxxx opened 7 months ago
too fast to see the log before it closes
package main
import (
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/proto"
"fmt"
"time"
"log"
)
func main() {
u := "https://ubuntu.com/core"
page := rod.New().MustConnect().MustPage()
done := make(chan int)
go page.EachEvent(func(e *proto.RuntimeConsoleAPICalled) {
fmt.Println(page.MustObjectsToJSON(e.Args))
close(done)
})()
page.Timeout(30 * time.Second).MustNavigate(u).MustWaitNavigation()
log.Printf("waiting 10 sec")
time.Sleep(10 * time.Second)
log.Printf("finished waiting")
}
Even with delay, I only see the JS console.log. I would like to see the errors and warnings like ERR_NAME_NOT_RESOLVED
. How can I do that ? Thank you !
I can't get this error with the code you provide. How to reproduce ERR_NAME_NOT_RESOLVED?
Thanks for your answer. It was just an example. Here is a real example. The URL https://helpdesk.paessler.com/en/support/home returns all the errors below.
How can I get the same console messages with go-rod ?
package main
import (
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/proto"
"fmt"
"time"
"log"
)
func main() {
u := "https://helpdesk.paessler.com/en/support/home"
page := rod.New().MustConnect().MustPage()
done := make(chan int)
go page.EachEvent(func(e *proto.RuntimeConsoleAPICalled) {
fmt.Println(page.MustObjectsToJSON(e.Args))
close(done)
})()
page.Timeout(30 * time.Second).MustNavigate(u).MustWaitNavigation()
log.Printf("waiting 10 sec")
time.Sleep(10 * time.Second)
log.Printf("finished waiting")
}
Thank you for your time
To capture the browser log, add a handler for proto.LogEntryAdded events:
go page.EachEvent(func(e *proto.LogEntryAdded) {
msg, _ := json.Marshal(e.Entry)
fmt.Println(string(msg))
})()
Rod Version: v0.114.5
I would like to get the browser error logs/events such as
ERR_NAME_NOT_RESOLVED
when browsing URLs with the associated loaded network ressource URL. I can see an issue with the same question here https://github.com/go-rod/rod/issues/330, but the code sample above doesn't work. What am I doing wrong ? Thank you !