Puppeteer - Struggling with setting cookies? Getting an error that says "is missing the following properties from type 'CookieParam': name, value"?

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);
}

Answer №1

Instead of passing an array, you need to provide the cookies individually:

page.setCookie(cookie1, cookie2)

You can also spread them out like this:

page.setCookie(...cookies)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Move the divs within the overflow container by sliding them, then take out the initial element and append it to the end

Currently, when I utilize .appendTo(".wrapper") as shown in the code below, it eliminates the animation effect. My goal is to have the div on the far left slide out of view, triggering an overflow hidden effect, and then be placed at the end of the slide c ...

I encountered an issue with rendering static images when attempting to package my node-express app with pkg

Struggling to display an image from the public folder in my express app? I could use some guidance on configuring the path to properly render images or css files within the public folder when creating an executable file using pkg. Here's a snippet of ...

Switching from PHP to JavaScript before returning to PHP to establish and manage sessions

Currently, I am in the process of resolving an issue I am facing. The problem arises when utilizing the following code for someone trying to sign into the admin panel: <script> function myFunction() { //alert('you can type now, end ...

Is there a way to pass multiple PHP variables as parameters to a custom JavaScript function within an external module file?

Currently experimenting with three.js and WebGL. I'm attempting to pass references from the database to a custom JavaScript function in order to load a model, however I keep getting an alert message showing results as undefined. The JavaScript file is ...

Arrangement of code: Utilizing a Node server and React project with a common set of

Query I am managing: a simple react client, and a node server that functions as both the client pages provider and an API for the client. These projects are tightly integrated, separate TypeScript ventures encompassed by a unified git repository. The se ...

Exploring elements within a JavaScript array

I'm struggling to retrieve model objects from my view model. It seems like a JavaScript/KnockoutJS familiarity issue, so any guidance is welcomed. Here is the code snippet: <!-- VIEW --> <select data-bind="options: allTypes, ...

Using PHP to ascertain the requested dataType or responseType from the client

My ajax request is fairly simple: $.post('server.php',data, function (json) {console.log(json)},'json'); I have configured jQuery to expect json data based on the dataType setting. Question: Is the dataType parameter equivalent to re ...

What is the process for changing the value type of a function in an already existing record?

Trying to create a function that transforms the definitions of object functions into different, yet predictable, functions. For example: converter<{ foo: (n: number) => void, bar: (s: string) => void }>({ foo: fooFunction, bar: barFunc ...

Clarification on Regular Expressions

Looking to improve my java-script code for extracting words that occur after an "=" in a string. For example: string strOld="ActionDate=11/20/2014 12:00:00 AM "; strOld.substr(strOld.indexOf(type)).substr(type.length +1, strOld.substr(strOld.indexOf(typ ...

Make sure that spyOnProperty is used to create configurable properties using Object.defineProperty

After upgrading to Angular 9 (from 8.1) and Typescript 3.7 (from <3.6), I've come across an issue with the spyOnProperty method. This is how my service looks: class Backend { public get baseURL(): string { return 'http://baseurl.com/&a ...

When utilizing VueJs, it's not possible to retrieve a data property from within a function

I am encountering a challenge when trying to access the data property within the function. Despite my efforts, I seem to be missing something crucial and unable to pinpoint what it is. Here is my class: export default { name: "Contact", component ...

How to programmatically close a Bootstrap modal without using jQuery in JavaScript

Is there a way to make it so that I can close a Bootstrap modal with just one click instead of having to double click? Thanks! This is the code I'm currently using to close the Bootstrap modal using JavaScript: // To Close Modal document.getE ...

Vue randomly sets the prototype of props in its definition

When the same code with the identical data structure is passed to the prop, it randomly sets the prop as an array or an object. The following is the code fragment: const props = defineProps({ all: { type: Array, default: [], } }) ...

Mozilla struggles to interpret JSON data

When using Angular2 (RC4), I utilize this code snippet to retrieve data from my WebApi: getAppointment(id: number): Observable<Event> { return this._http.get(this._serviceUrl + 'get/' + id) .map(this.extractData) .catch ...

Is there a way to adjust the color of the spin buttons in Material UI Text Field when using type number?

When creating a number Text Field with Material UI, I noticed that the colors of the spin buttons are not adhering to my theme. Here is an example code snippet from the Material UI documentation that showcases the issue: <TextField id="outlined- ...

Step-by-step guide for implementing the Export Pdf feature for a Customized Edit Form in OrgChartJS by Balkan

I recently created a personalized Edit form using OrgChartJS by Balkan, but now I'm facing difficulties in exporting that edit form to PDF. Can anyone provide guidance or assistance? Here is a snippet from my JS file: var chart; fetch('url&a ...

Enclosing Material UI's DataGrid GridActionsCellItem within a custom wrapper component triggers a visual glitch if showInMenu is enabled

Here is how my MUI DataGrid columns are structured: const columns = [ { field: "name", type: "string" }, { field: "actions", type: "actions", width: 80, getActions: (params) => [ ...

My goal is to create a backend platform similar to Kinvey, utilizing Node.js, Sails.js, and MongoDB

Hey there! I'm looking to develop a backend service similar to Kinvey (but for HTML and HTML5) using node.js, sails.js, and mongodb. With this service, I want the capability to create, post, update, and delete data just like you can with Kinvey. Here& ...

Vue component doesn't update reactively until the template value changes

I have a child component in my Vue application that utilizes Vuex for managing certain values. Currently, when I trigger an action in the parent component, it should also trigger the child component. This is achieved by passing an active boolean prop to t ...

When attempting to navigate using router.navigate in Angular 6 from a different component, it triggers a refresh

My routing setup is structured as follows: Main App-routing module const routes: Routes = [ { path: '', redirectTo: environment.devRedirect, pathMatch: 'full', canActivate: [AuthenticationGuard] }, { path: &a ...