Read and write cookies like a bot
async function login() { return fetch('<some_url>/login', { 'headers': { 'accept': '*/*', 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8', 'cookie': '',, }, 'body': 'username=foo&password=bar', 'method': 'POST', }); } (async() => { const loginResponse = await login(); const loginCookies = parseCookies(loginResponse); })();
You can include: accept-language , user-agent , referer , accept-encoding , etc. (Check out the Chrome DevTools request example)
For some reason, the resulting site selection request cookies are not compatible with new requests, but we can analyze them as follows:
function parseCookies(response) { const raw = response.headers.raw()['set-cookie']; return raw.map((entry) => { const parts = entry.split(';'); const cookiePart = parts[0]; return cookiePart; }).join(';'); }
Pass cookies in your future requests through the same headers:
return fetch('<some_url>/dashboard', { 'headers': { 'accept': '*/*', 'cookie': parsedCookies, }, 'method': 'GET', });
zurfyx
source share