playwright-community / playwright-go

Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
https://playwright-community.github.io/playwright-go/
MIT License
1.94k stars 144 forks source link

APIRequestContextFetch does not seem to populate cookie and update cookie from response #419

Open chronicom opened 4 months ago

chronicom commented 4 months ago

According to the playwright official site "Fetch Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects. JSON objects can be passed directly to the request. "

However when I call page.Request().Fetch(URL, opts)

it does not seem to populate the the coookie from the browser context. I tried to manually encode the cookie into the header and was able to get the response from the API endpoint. The problem remains is that the cookie from the browser context does not automatically updated from the response. Did I miss something or I made the Fetch call in a wrong way?

canstand commented 4 months ago

pls try this:

page.Context().AddCookies([]playwright.OptionalCookie{
  {
    Name:  "foo",
    Value: "bar",
    URL:   playwright.String(server.PREFIX),
  }

page.Request().Fetch...
chronicom commented 4 months ago

pls try this:

page.Context().AddCookies([]playwright.OptionalCookie{
  {
    Name:  "foo",
    Value: "bar",
    URL:   playwright.String(server.PREFIX),
  }

page.Request().Fetch...

Hi Canstand,

Thank you for the response. The thing is that the cookie is atually correct in page.Context().Cookies(). There is no need to add optional cookie. The porblem is that when I make the call, for example, page.Request().Get(URL) it does not send the get request with cookie :( I have also looked into the code of get() and fetch() function. It does not seem to populate the cookie from context anywhere.