Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
chronicom opened this issue Feb 12, 2024 · 2 comments

Comments

@chronicom
Copy link

chronicom commented Feb 12, 2024

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
Copy link
Collaborator

pls try this:

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

page.Request().Fetch...

@chronicom
Copy link
Author

chronicom commented Feb 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants