Updated chrome protocol library

This commit is contained in:
Musab Gültekin
2019-11-16 20:34:57 +03:00
parent 6645820408
commit cbca22fefb
4 changed files with 17 additions and 22 deletions

View File

@ -169,6 +169,7 @@ func (c *Client) DoRequestChrome(req *Request) (*Response, error) {
var body string
var res *network.Response
// Set remote allocator or use local chrome instance
ctx := context.Background()
if c.opt.RemoteAllocatorURL != "" {
ctx, _ = chromedp.NewRemoteAllocator(ctx, c.opt.RemoteAllocatorURL)
@ -183,6 +184,7 @@ func (c *Client) DoRequestChrome(req *Request) (*Response, error) {
var reqID network.RequestID
chromedp.ListenTarget(ctx, func(ev interface{}) {
switch ev.(type) {
// Save main request ID to get response of it
case *network.EventRequestWillBeSent:
reqEvent := ev.(*network.EventRequestWillBeSent)
if _, exists := reqEvent.Request.Headers["Referer"]; !exists {
@ -190,6 +192,7 @@ func (c *Client) DoRequestChrome(req *Request) (*Response, error) {
reqID = reqEvent.RequestID
}
}
// Save response using main request ID
case *network.EventResponseReceived:
if resEvent := ev.(*network.EventResponseReceived); resEvent.RequestID == reqID {
res = resEvent.Response

View File

@ -7,9 +7,7 @@ import (
func TestResponse_JoinURL(t *testing.T) {
req, _ := NewRequest("GET", "https://localhost.com/test/a.html", nil)
resp := Response{
Response: nil,
Request: req,
}
resp := Response{Request: req}
assert.Equal(t, "https://localhost.com/source", resp.JoinURL("/source"))
}