Accessing cookies from a chrome app

老子叫甜甜 提交于 2019-12-18 15:54:40

问题


I can see that when I issue an xhr from my chrome app that it sends some cookies, and these cookies are kept track of in the app. Servers sending set-cookie headers are updating them correctly. I need to read a cookie though, and I tried using the "cookies" permission but chrome yelled at me... Is there another api I can use?

edit: I am using the new packaged apps.


回答1:


Cookies is apparently a dark area of Chrome Packaged Apps.

With Extensions, the extension shares the cookie jar with normal browsing activities. For Packaged Apps, each app has a separate jar.

The current behaviour seems to be that XHR requests to sites specified in the manifest in the permissions section do set cookies in this jar but there is no way how to get rid of them, except reinstalling the app. There is no API for Packaged Apps to manage cookies and their cookies do not show in Developer tools or about://settings/cookies page.

the crbugs include

https://code.google.com/p/chromium/issues/detail?id=70391 https://code.google.com/p/chromium/issues/detail?id=152758 https://code.google.com/p/chromium/issues/detail?id=157474

and these two issues filled in response to this SO question

https://code.google.com/p/chromium/issues/detail?id=236585 https://code.google.com/p/chromium/issues/detail?id=335934




回答2:


I had a similar issue where security restrictions on XHR in a packaged app with chrome.socket api permission seemed overbearing. See Setting "unsafe" headers in packaged app XHR

I ended up creating a "shim" xhr object for my use case, though it doesn't handle e.g. chunked encoding. You might find it useful: https://github.com/kzahel/jstorrent/blob/fresh/js/chromesocketxhr.js

I ended up filing a bug on crbug: https://code.google.com/p/chromium/issues/detail?id=335934



来源:https://stackoverflow.com/questions/16071681/accessing-cookies-from-a-chrome-app

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