Puppeteer get 3rd party cookies

那年仲夏 提交于 2020-01-02 04:34:09

问题


How can I get 3rd party cookies from website using puppeteer?

For first party I know I can use await page.cookies()


回答1:


I was interested to know the answer so have found a solution too, it works for the current versions of Chromium 75.0.3765.0 and puppeteer 1.15.0 (updated May 2nd 2019).

Using internal puppeteer page._client methods we can make use of Chrome DevTools Protocol directly:

(async() => {
  const browser = await puppeteer.launch({});
  const page = await browser.newPage();
  await page.goto('https://stackoverflow.com', {waitUntil : 'networkidle2' });

  // Here we can get all of the cookies
  console.log(await page._client.send('Network.getAllCookies'));

})();

In the object returned there are cookies for google.com and imgur.com which we couldn't have obtained with normal browser javascript:



来源:https://stackoverflow.com/questions/50252943/puppeteer-get-3rd-party-cookies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!