turrican_34
turrican_34

Reputation: 769

Puppeteer: Network.setCookie returns invalid string param

I'm learning to use the CDPSession class in Puppeteer, but I'm having trouble with using the method parameters of the dev tools protocol.

Dev Tools Network

The Network.setCookie section of the Dev tools docs show the params for setting the name cookie are: name string, but when I do this it returns an error: Error: Protocol error (Network.setCookie): Invalid parameters value: string value expected.

What am I doing wrong?

const puppeteer = require('puppeteer');

puppeteer.launch().then(async browser => {
    const page = await browser.newPage();
    const client = await page.target().createCDPSession();
    await client.send('Network.enable');
    const setCookie = await client.send('Network.setCookie', {
        name: 'mycookie'
    });

    console.log("Set Cookie: " + setCookie.success);
    await page.goto('https://example.com');
    await browser.close();
});

Upvotes: 2

Views: 12312

Answers (1)

turrican_34
turrican_34

Reputation: 769

The answer was simple. I also needed to set the value and url or domain params.

const setCookie = await client.send ( 'Network.setCookie', { 
    name: 'mycookie', value: 'Hello', domain: 'https://example.com' 
});

Upvotes: 1

Related Questions