Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Greasemonkey detect private browsing mode?

I need to make my Greasemonkey script behave differently if it is currently running in a Firefox Private Browsing window. Is it possible to detect this from Greasemonkey? If not, then is it possible to have it not run at all in Private Browsing mode?

EDIT: One reason I want to do that is that normally the script makes AJAX requests, which include information about the visited page and the server-side may store that information (which is OK when browsing in normal mode). If the user is in Private Browsing, though, I don't want the server-side to have the information that the user is visiting the page, so I want to have it not make these requests in that case.

like image 345
user3321300 Avatar asked Feb 18 '14 00:02

user3321300


People also ask

Can Private Browsing be detected?

Private browsing only prevents your web browser from saving your browsing history. This means anyone else who uses your computer will not be able to see your online activity. Unfortunately, it doesn't guarantee security—your activity can still be tracked by websites.

Does Tampermonkey work in incognito?

An important thing to know if you work with Tampermonkey in incognito mode: your changes made in incognito mode won't appear in normal mode, and vice versa: you have to close all your private windows if you want to try your latest changes made in public mode.

How do I know if my Safari browser is in private mode?

You can easily confirm that you're in Private Browsing Mode by checking that the search field bar is gray or displays the word Private. to open a different Tab Group from the menu at the bottom of your screen. The private sites reappear the next time you use Private Browsing Mode.


1 Answers

From within a plugin in Firefox, you can detect if the browser is in Private Browsing Mode with the below code taken from Mozilla's developer docs. This is however an internal API only accessible from within plugins, not websites or third party scripts.

There is no gurantee this will help you as I am not sure if Grease Monkey expose the Components API in Firefox for use within a GM script or not. Initial searching seems to turn up nothing of the sort.

try {
    var pbs = Components.classes["@mozilla.org/privatebrowsing;1"]
                    .getService(Components.interfaces.nsIPrivateBrowsingService);

    var inPrivateBrowsingMode = pbs.privateBrowsingEnabled;

    if (!inPrivateBrowsingMode) {
    /* save private information */
    }
} catch(e){
  alert("Error!");
}  
like image 144
Dwayne Charrington Avatar answered Sep 18 '22 15:09

Dwayne Charrington