Extension needs to determine if it is run in private mode

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

Extension needs to determine if it is run in private mode

Post by JackPollack »

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/417 ... ent-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: 6404
Joined: February 3rd, 2009, 6:29 pm

Re: Extension needs to determine if it is run in private mod

Post by morat »

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: 78
Joined: August 30th, 2006, 7:11 pm

Re: Extension needs to determine if it is run in private mod

Post by JackPollack »

No manifest, yes it is a legacy extension.

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

Thank you
Locked