'How to get data from API fetch using playwirght .NET
I'm trying to get an answer the response from an api using the fetch command that i get from chrome developer tools but i get an error when i feed it to playwright :
link = fetch("https://api.xx.com/graphql/public?", {
"headers": {
"accept": "*/*",
"accept-language": "fr-FR",
"authorization": "Bearer
YzA1ZTBiYjkyNmJkNTNjMGQ2N2YyMWU5NzJjMjkwZTdiYTRkNWFlYTI5NTAyMGZlNGEwMzFhMDM0NWUyODU5Ng",
"content-type": "application/json",
"sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"100\", \"Google Chrome\";v=\"100\"",
"sec-ch-ua-mobile": "?1",
"sec-ch-ua-platform": "\"Android\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
"Referer": "https://www.xx.fr/",
"Referrer-Policy": "origin-when-cross-origin"
},
"method": "POST",
"mode": "cors",
"credentials": "include"
});
And then i use the EvaluateAsync method :
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Webkit.LaunchAsync();
var page = await browser.NewPageAsync();
var response = await page.EvaluateAsync<string>(link);
Error :
Unhandled exception. Microsoft.Playwright.PlaywrightException: SyntaxError:
Unexpected identifier 'Not'. Expected '}' to end an object literal.
at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](String
guid, String method, Object args) in /_/src/Playwright/Transport/Connection.cs:line
161
at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action,
Boolean isInternal) in /_/src/Playwright/Transport/Connection.cs:line 487
at Microsoft.Playwright.Core.Frame.EvaluateAsync[T](String script, Object arg) in
/_/src/Playwright/Core/Frame.cs:line 483
But this doesn't work, is it an error with the string formatting ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|