I need to get all the cookies from the browser

前端 未结 9 1294
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 09:52

I need to get all the cookies stored in my browser using JavaScript. How can it be done?

相关标签:
9条回答
  • 2020-12-04 10:27

    To retrieve all cookies for the current document open in the browser, you again use the document.cookie property.

    0 讨论(0)
  • 2020-12-04 10:28

    You cannot. By design, for security purpose, you can access only the cookies set by your site. StackOverflow can't see the cookies set by UserVoice nor those set by Amazon.

    0 讨论(0)
  • 2020-12-04 10:31

    Since the title didn't specify that it has to be programmatic I'll assume that it was a genuine debugging/privacy management issue and solution is browser dependent and requires a browser with built in detailed cookie management toll and/or a debugging module or a plug-in/extension. I'm going to list one and ask other people to write up on browsers they know in detail and please be precise with versions.

    Chromium, Iron build (SRWare Iron 4.0.280)

    The wrench(tool) menu: Options / Under The Hood / [Show cookies and website permissions] For related domains/sites type the suffix into the search box (like .foo.tv). Caveat: when you have a node (site or cookie) click-highlighted only use [Remove] to kill specific subtrees. Using [Remove All] will still delete cookies for all sites selected by search and waste your debugging session.

    0 讨论(0)
  • 2020-12-04 10:32

    Modern approach.

    let c = document.cookie.split(";").reduce( (ac, cv, i) => Object.assign(ac, {[cv.split('=')[0]]: cv.split('=')[1]}), {});
    
    console.log(c);
    

    ;)

    0 讨论(0)
  • 2020-12-04 10:34

    If you develop browser extensions you can try browser.cookies.getAll()

    0 讨论(0)
  • 2020-12-04 10:38

    What you are asking is possible; but that will only work on a specific browser. You have to develop a browser extension app to achieve this. You can read more about chrome api to understand better. https://developer.chrome.com/extensions/cookies

    0 讨论(0)
提交回复
热议问题