Safari 扩展程序如何知道隐私浏览模式是否已打开?
我正在编写一个 Safari 扩展,并希望当用户打开私人浏览模式时它有不同的行为(我想尊重这种私人模式)。
我在苹果的文档中没有发现这一点。
我知道此线程中的讨论:
,建议使用(与浏览器无关的)js-CSS 技巧来检测隐私浏览模式,但希望 Safari 中有一些内置的钩子可以用于我的扩展。
有什么想法吗?
I'm writing a Safari extension and want it to behave differently when the user turns on Private Browsing mode (I want to respect this private mode).
I found no mention of this in Apple's docs.
I'm aware of the discussion in this thread:
Detecting if a browser is using Private Browsing mode
which suggests using a (browser-agnostic) js-CSS trick to detect private-browsing mode, but was hoping there's some hook built in to Safari that I could use for my extension.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以查询布尔值
safari.application.privateBrowsing.enabled
来检查是否启用了隐私浏览。您还可以附加事件侦听器以在激活或停用隐私浏览时触发自定义代码。
来源: 苹果文档
You can query the boolean
safari.application.privateBrowsing.enabled
to check if private browsing is enabled or not.You can also attach event listeners to trigger custom code when private browsing is activated or deactivated.
Source: Apple Docs
所有私有模式都会忽略浏览器使用的 cookiejar 的当前状态。使用 evercookie 之类的东西来跟踪特定的浏览器以及它如何管理其各种会话 ID。例如,如果您有一个 60 年后过期的 http cookie,并且该 cookie 值未出现在对服务器的请求中,那么您就知道 cookie 值已被刷新,或者它们处于私有模式。这将需要您进行更多的实验,但这个方向将是检测浏览器中私有模式的使用的通用方法。
All private modes will ignore the current status of the cookiejar used by the browser. Use something like an evercookie to keep track of a specific browser and how it manages its various session id's. For instance, if you have an http cookie that expires in 60 years, and this cookie value isn't present in a request to your server, then you know either the cookie values have been flushed or they are in private mode. This will require a bit more experimentation on your side, but this direction will be a general method to detect use of private mode in browsers.