godet: get main status code
Hi. I tried to get status code
of the requested url
with a code like this:
...
remote.CallbackEvent("Network.responseReceived", func(params godet.Params) {
resp := params.Map("response")
url = resp["url"].(string)
statusCode = int(resp["status"].(float64))
fmt.Println(statusCode, url)
})
tab, err := remote.NewTab("https://www.somewhere.com")
...
but when I run it, i get this:
200 https://www.somewhere.com/Content/css?v=nzhr89jyV
200 https:/www.somewhere.com/bundles/angularjs?v=7xwsovO
200 https://www.somewhere.com/bundles/js?v=C3adeImoIV
200 https://www.somewhere.com/bundles/app?v=vp6dm1p3JfVY
200 https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js
...
the url https://www.somewhere.com is not returned among them. how can I get the page’s status code?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (7 by maintainers)
It’s because you are using
remote.NewTab()
. This will open a new tab with the URL and then connect the debugger to it. In the time it takes the debugger to connect the page will have already loaded a whole bunch of resources for which you missed the events.You need to use
remote.Navigate()
to navigate in the currently connected tab. Or you need to create the new tab usingremote.NewTab("about:blank")
and when that returns useremote.Navigate()
.