add cookies

This commit is contained in:
Jorrin
2024-02-06 20:15:45 +01:00
parent 34c3709b2e
commit 710b40aa8a
3 changed files with 20 additions and 2 deletions

View File

@@ -69,11 +69,18 @@ const handler: PlasmoMessaging.MessageHandler<Request, Response<any>> = async (r
const contentType = response.headers.get('content-type');
const body = contentType?.includes('application/json') ? await response.json() : await response.text();
const cookies = await (chrome || browser).cookies.getAll({
url: response.url,
});
res.send({
success: true,
response: {
statusCode: response.status,
headers: Object.fromEntries(response.headers.entries()), // Headers object isn't serializable
headers: {
...Object.fromEntries(response.headers.entries()),
'Set-Cookie': cookies.map((cookie) => `${cookie.name}=${cookie.value}`).join('; '),
},
body,
finalUrl: response.url,
},