木偶获得第三方Cookie [英] Puppeteer get 3rd-party cookies

查看:123
本文介绍了木偶获得第三方Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Puppeteer从网站获取第三方Cookie?



对于第一方,我知道我可以使用:

 等待页面.cookies()


解决方案

我很想知道答案,因此也找到了解决方案,它适用于当前版本的Chromium 75.0.3765.0和puppeteer 1.15.0 (2019年5月2日更新)



使用


How can I get 3rd-party cookies from a website using Puppeteer?

For first party, I know I can use:

await page.cookies()

解决方案

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:

这篇关于木偶获得第三方Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆