在OS X中每个WebView单独的cookie jar [英] Separate cookie jar per WebView in OS X

查看:119
本文介绍了在OS X中每个WebView单独的cookie jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图实现在Mac Os X中为每个WebView创建一个唯一的(不共享的)cookie jar的目的(cookie管理对iOS不同)。

I've been trying to achieve the goal of having a unique (not shared) cookie jar per WebView in Mac Os X (cookies management works different for iOS).

在阅读了很多StackOverflow问题和挖掘文档,我发现最近的解决我的问题在这篇文章:

After reading a lot of StackOverflow question and digging the docs, I found the closest solution to my problem in this articles:

  • http://cutecoder.org/programming/implementing-cookie-storage/ (how to handle HTTP cookies)
  • http://cutecoder.org/programming/handling-cookies-javascript-custom-jar/ (how to handle JavaScript document.cookie cookies)

使用它们: https://github.com/jjconti/swift-webview-isolated

基本思想是从WebResourceLoadDelegate和WebPolicyDelegate协议实现必要的方法,并使用BSHTTPCookieStorage存储和检索Cookie。此外,我的示例应用程序允许保存cookieStorage对象,所以它可以重新加载在未来的执行。

The basic idea is to implement the necessary methods from the WebResourceLoadDelegate and WebPolicyDelegate protocols and use BSHTTPCookieStorage to store and retrieve cookies. Additionally, my example app allows saving the cookieStorage object so it can be reloaded in future executions.

不幸的是,该应用程序不工作确定在每个网站文章的目标是一个特定的网站)。例如Gmail和NewRelic,您会在登录后(或在执行某些操作后)立即注销。

Unfortunately, the app doesn't work ok in every website (the author of the articles was targeting one particular web site). For example Gmail and NewRelic you're immediately logged out after login (or after doing some actions). That makes me suspect a bug in the cookie storage implementation which I haven't been able to find yet.

如果有东西缺失,有人可以指点我吗?

Could someone point me if something is missing?

推荐答案

问题是没有JS级别的cookie隔离。 document.cookie仍指向共享的cookie jar。要实现一个真正的cookie隔离的webview,你必须覆盖文档的cookie属性。

The problem is there are no JS level cookie isolation. document.cookie still point to the shared cookie jar. To implement a true cookie isolated webview, you must override the cookie property of document.

你可以尝试我的实现:
http://cyyuen.github.io/ADCookieIsolatedWebView

You may try my implementation: http://cyyuen.github.io/ADCookieIsolatedWebView

它适用于网站使用document.cookie获取Cookie,如Dropbox.com。但是,设置器未实现。

It works for the site using document.cookie to get the cookie such as Dropbox.com. However, the setter is not implemented.

这篇关于在OS X中每个WebView单独的cookie jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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