Reputation: 769
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.
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
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