Here is my cookie variable:
const cookies = [{
domain: ".example.io",
expirationDate: 1234567890,
hostOnly: true,
httpOnly: true,
name: "cookie_name",
path: "/",
sameSite: "strict",
secure: true,
session: false,
storeId: "1",
value: "abc123xyz",
id: 2,
},
This is how I am calling setCookie from my Puppeteer script:
await page.setCookie(cookies);
However, I am encountering an error message:
Error TS2345: Argument of type '{...}' is not assignable to parameter of type 'CookieParam'.
Type '{...}' is missing the following properties from type 'CookieParam': name, value
Even though it seems like name and value are not missing from the cookie object...
I have tried changing types, searching for the 'CookieParams' type, and adding quotes around the cookie keys, but I still can't resolve the issue. What could be the problem that I am overlooking?
Below is the full code snippet:
import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
const defaultPuppeteerOptions = {headless:false};
const exampleUrl = 'https://example.com';
const cookies = [{
domain: ".example.io",
expirationDate: 1234567890,
hostOnly: true,
httpOnly: true,
name: "cookie_name",
path: "/",
sameSite: "lax",
secure: true,
session: false,
storeId: "1",
value: "abc123xyz",
id: 2,
},
]
export default async function Start() {
const browser = await puppeteer.launch(defaultPuppeteerOptions);
const page = await browser.newPage();
await page.goto(exampleUrl);
await page.setCookie(cookies);
}