Reputation: 121
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.
Upvotes: 12
Views: 1830
Reputation: 6850
This feature is implemented since Greasemonkey 3.8 - https://github.com/greasemonkey/greasemonkey/issues/2199
You can use GM_info.isPrivate
to check if the userscript is running in private mode window.
Upvotes: 2
Reputation: 6622
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!");
}
Upvotes: 1