Javascript 访问所有存储的 cookie

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5124030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 15:45:27  来源:igfitidea点击:

Access all stored cookies

javascriptcookiesgoogle-chromeconsolelocal

提问by dan

I want to access my Chrome stored cookies from the JavaScript console. Is this possible?

我想从 JavaScript 控制台访问我的 Chrome 存储的 cookie。这可能吗?

回答by ThiefMaster

If you only need the cookies for the active site: Have a look at document.cookie. It contains semicolon-separated key=valuepairs.

如果您只需要活动站点的 cookie:请查看document.cookie. 它包含以分号分隔的key=value对。

Edit: Note that due to security concerns you can't access cookies from a different domain. When you run something from the console, it's the equivalent of it running directly from the page, so since they don't want a spam site getting your Facebook credentials, you'll have to go to each website separately.

编辑:请注意,出于安全考虑,您无法访问来自不同域的 cookie。当您从控制台运行某些内容时,它相当于直接从页面运行,因此,由于他们不希望垃圾邮件站点获取您的 Facebook 凭据,因此您必须分别访问每个网站。

回答by Radium

Easiest way to go:

最简单的方法:

console.log(document.cookie);

回答by Marcello

Using Chrome, if you have the possibility to use other tool instead of only the Console, you can access all stored cookies and see detailed information using the tab "Resources". To do this:

使用 Chrome,如果您可以使用其他工具而不仅仅是控制台,您可以访问所有存储的 cookie 并使用“资源”选项卡查看详细信息。去做这个:

  • Open Developer Tools (F12)
  • Click on "Resources" tab
  • Expand the "Cookies" list item
  • Click on the website address
  • 打开开发者工具 ( F12)
  • 单击“资源”选项卡
  • 展开“Cookies”列表项
  • 点击网址