playwright-go icon indicating copy to clipboard operation
playwright-go copied to clipboard

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

Open chronicom opened this issue 1 year ago • 2 comments

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?

chronicom avatar Feb 12 '24 10:02 chronicom

pls try this:

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

page.Request().Fetch...

canstand avatar Feb 26 '24 10:02 canstand

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.

chronicom avatar Feb 28 '24 17:02 chronicom