Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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-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?

like image 234
Amos Avatar asked Oct 18 '10 16:10

Amos


People also ask

Do Safari extensions work in private mode?

Although Safari has a "Private" mode, Safari does not disable add-ons by default in private mode. However, Safari has a very simple setting to turn off all extensions. In the "Preferences" window, select "Extensions" and choose the "Off" option.

How do I know if private browsing mode is on?

You can quickly tell if you are using Private Browsing as the url/search bar will appear with a dark theme instead of white or gray for standard windows. Also, the white highlight around Private shown above on the right) means it is turned on. Tap the + symbol at the bottom middle of the screen and start browsing.

Is private Safari traceable?

The answer is no. Private browsing does not guarantee security and can easily be traced. As stated above, if you turn on Private Browsing on your iPhone, the details of your browsing will not be saved on your iPhone. This means that anyone else who uses your iPhone will not know your online activity.


1 Answers

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

like image 87
David Tuite Avatar answered Nov 15 '22 04:11

David Tuite