开发者

How can a Safari extension know if Private Browsing mode is on?

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-agn开发者_如何转开发ostic) 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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜