MozillaZine


Extension needs to determine if it is run in private mode

Talk about add-ons and extension development.
JackPollack
 
Posts: 77
Joined: August 30th, 2006, 7:11 pm

Post Posted September 22nd, 2022, 5:25 am

I'm trying to modify an old FireFox extension (for FF 50). I need to add to the extension the ability to determine if it is in a regular browser window or a private window.

According to this post https://stackoverflow.com/questions/41709369/detect-incognito-mode-in-an-content-script should be able to use
Code: Select all
console.log(browser.extension.inIncognitoContext);


When I try it in the web console or in my extension, I get 'ReferenceError: browser is not defined'

Some help getting my extension to determine browser mode would be appreciated. Either using above idea, or I saw in my searching there was mention (but no examples) of API's that extensions could use to determine if they were in private mode.

morat
 
Posts: 5340
Joined: February 3rd, 2009, 6:29 pm

Post Posted September 22nd, 2022, 6:39 am

The browser.extension.inIncognitoContext is a WebExtension property.

browser.extension.inIncognitoContext
http://developer.mozilla.org/docs/Mozil ... itoContext

Code: Select all
console.log(browser.extension.inIncognitoContext);

I cannot test the WebExtension code snippet in the web console or browser console.

I can test the WebExtension code snippet in about:debugger with the uBlock Origin addon.

Does your addon have a manifest.json file? If not, then it's a legacy addon.

Try running the following code in the browser console.

Code: Select all
console.log(PrivateBrowsingUtils.isWindowPrivate(window));

JackPollack
 
Posts: 77
Joined: August 30th, 2006, 7:11 pm

Post Posted September 22nd, 2022, 9:01 am

No manifest, yes it is a legacy extension.

worked perfectly:
console.log(PrivateBrowsingUtils.isWindowPrivate(window));

Thank you

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 3 guests