go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.
https://go-rod.github.io
MIT License
5.23k stars 345 forks source link

cookie not take effect #876

Open RonaldinhoL opened 1 year ago

RonaldinhoL commented 1 year ago

i am set cookie like this

for i, item := range cookies {
        c := item.Cookie
        networkCookie := proto.NetworkCookieParam{
            Name:  c.Name,
            Value: c.Value,
            URL:      item.U.String(),
            Domain:   item.Domain,
            Path:     c.Path,
            HTTPOnly: c.HttpOnly,
            Secure:   c.Secure,
            SameSite: proto.NetworkCookieSameSite(cookiejar.SameSiteIntToStr(c.SameSite)),
            Expires: proto.TimeSinceEpoch(c.Expires.Unix()),
        }
        err = browser.SetCookies([]*proto.NetworkCookieParam{&networkCookie})
        self.Logger().Debugf("set chrome cookie %d: %s, %s %s %s", i, c.Name, c.Domain, c.Expires, item.U.String())
        if err != nil {
            self.Logger().Errorf("%s, set chrome cookie %d: %+v", err.Error(), i, c)
        }
    }

the log show:


set chrome cookie 1: BAIDUID, .baidu.com 2024-05-17 03:22:24 +0000 GMT https://www.baidu.com  
set chrome cookie 2: BIDUPSID, .baidu.com 2037-12-31 23:55:55 +0000 GMT https://www.baidu.com  
set chrome cookie 3: PSTM, .baidu.com 2037-12-31 23:55:55 +0000 GMT https://www.baidu.com  
set chrome cookie 4: BDSVRTM,  0001-01-01 00:00:00 +0000 UTC https://www.baidu.com  
set chrome cookie 5: BD_HOME,  0001-01-01 00:00:00 +0000 UTC https://www.baidu.com  
set chrome cookie 6: H_PS_PSSID, .baidu.com 0001-01-01 00:00:00 +0000 UTC https://www.baidu.com  

but the browser only send

GET / HTTP/1.1
Host: www.baidu.com
Connection: keep-alive
sec-ch-ua: "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cookie: BDSVRTM=0; BD_HOME=1
Pragma: no-cache
Cache-Control: no-cache

idk why,is it a bug?

github-actions[bot] commented 1 year ago

Please add a valid Rod Version: v0.0.0 to your issue. Current version is v0.113.0

Please fix the format of your markdown:

2 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
2 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
25 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
25 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
35:26 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1]
36 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```"]
36 MD040/fenced-code-language Fenced code blocks should have a language specified [Context: "```"]
59 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2]

generated by check-issue

RonaldinhoL commented 1 year ago

Rod Version: github.com/go-rod/rod v0.113.0

ysmood commented 1 year ago

host is wrong, https and http

RonaldinhoL commented 1 year ago

host is wrong, https and http

host is host, not include protocal

ysmood commented 1 year ago

Could you follow the template and give a full test that can actually run?

https://github.com/go-rod/rod/blob/main/.github/ISSUE_TEMPLATE/question.md

Fly-Playgroud commented 1 year ago

please accroding to this issue #777 do some preview checking for it