Safari 扩展程序如何知道隐私浏览模式是否已打开?

发布于 2024-09-27 15:06:37 字数 342 浏览 0 评论 0原文

我正在编写一个 Safari 扩展,并希望当用户打开私人浏览模式时它有不同的行为(我想尊重这种私人模式)。

我在苹果的文档中没有发现这一点。

我知道此线程中的讨论:

Detecting if a浏览器正在使用隐私浏览模式

,建议使用(与浏览器无关的)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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半暖夏伤 2024-10-04 15:06:37

您可以查询布尔值safari.application.privateBrowsing.enabled来检查是否启用了隐私浏览。

您还可以附加事件侦听器以在激活或停用隐私浏览时触发自定义代码。

safari.application.privateBrowsing.addEventListener('activate', function(e) {
  console.log("Private browsing activated");
});

safari.application.privateBrowsing.addEventListener('deactivate', function(e) {
  console.log("Private browsing deactivated");
});

来源: 苹果文档

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.

safari.application.privateBrowsing.addEventListener('activate', function(e) {
  console.log("Private browsing activated");
});

safari.application.privateBrowsing.addEventListener('deactivate', function(e) {
  console.log("Private browsing deactivated");
});

Source: Apple Docs

残月升风 2024-10-04 15:06:37

所有私有模式都会忽略浏览器使用的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文