New "private browsing" mode - how to use from page mod?

<<

nagle

Posts: 188

Joined: Fri Oct 23, 2009 10:14 am

Post Fri Mar 22, 2013 2:13 pm

New "private browsing" mode - how to use from page mod?

The way the new per-window "private browsing" scheme is set up appears to be incompatible with SDK-based add-ons.

An SDK-based access method for per-window private browsing information does not seem to be documented. There's some support for it within the SDK, marked as "unstable", at the undocumented function "isWindowPBEnabled" in private-browsing/util.js of the 1.13.2 SDK. ("Unstable" is not a valid value for SDK components, according to the new SDK "dev guide". The only allowed values are "Experimental", "Stable", and "Deprecated"). A Google search for "isWindowPBEnabled" does not show it mentioned in any documentation.

Even with that function, it's not clear what to do. In the add-on code, a PageMod call to launch a content script never sees a window handle. So there's no obvious place to make that test. There's no way to prevent loading of a content script in private browsing mode, given the way the PageMod API is designed. After launching a content script, all that the add-on code can do is respond to messages over ports. Window information is not available via that route.

Within a content script, there's no way to test for private browsing mode, since add-on side APIs cannot be called from the content script.

Please advise.
<<

wbamberg

Posts: 232

Joined: Thu Jun 23, 2011 4:08 pm

Post Fri Mar 22, 2013 2:49 pm

Re: New "private browsing" mode - how to use from page mod?

nagle wrote:The way the new per-window "private browsing" scheme is set up appears to be incompatible with SDK-based add-ons.

An SDK-based access method for per-window private browsing information does not seem to be documented. There's some support for it within the SDK, marked as "unstable", at the undocumented function "isWindowPBEnabled" in private-browsing/util.js of the 1.13.2 SDK. ("Unstable" is not a valid value for SDK components, according to the new SDK "dev guide". The only allowed values are "Experimental", "Stable", and "Deprecated"). A Google search for "isWindowPBEnabled" does not show it mentioned in any documentation.

Even with that function, it's not clear what to do. In the add-on code, a PageMod call to launch a content script never sees a window handle. So there's no obvious place to make that test. There's no way to prevent loading of a content script in private browsing mode, given the way the PageMod API is designed. After launching a content script, all that the add-on code can do is respond to messages over ports. Window information is not available via that route.

Within a content script, there's no way to test for private browsing mode, since add-on side APIs cannot be called from the content script.

Please advise.


The stuff in the SDK for coping with per-window private browsing is new for SDK 1.14, which is due to be released on Tuesday, so it is not yet documented in 1.13.2. You can read the docs by downloading the 1.14 release candidate (this RC has a bug that might make it not usable for you, but that won't affect cfx docs). Most of the information is in the API doc for the private-browing module.

Basically:

* from 1.14 you have to opt into seeing private windows by including a key in package,json like: `"permissions": {"private-browsing": true}`. If you don't opt in, you'll never see them, and your page mods will not attach content scripts to them. If you don't need your add-on to see private windows, that's the least-work way to work with it. You will still have to repack your add-on with 1.14, when that is released (we'll try to repack them automatically, but if we can't we'll ask you to).

* if you do need your add-on to see private windows, and you need to differentiate between private and non-private windows, you can ask private-browsing whether a worker is associated with a private window using isPrivate(worker):

  Code:
var pageMod = require("sdk/page-mod");
var privateBrowsing = require("sdk/private-browsing");
 
var loggingScript = "self.port.on('log-content', function() {" +
                    "  console.log(document.body.innerHTML);" +
                    "});";
 
function logPublicPageContent(worker) {
  if (privateBrowsing.isPrivate(worker)) {
    console.log("private window, doing nothing");
  }
  else {
    worker.port.emit("log-content");
  }
}
 
pageMod.PageMod({
  include: "*",
  contentScript: loggingScript,
  onAttach: logPublicPageContent
});



Also note that due to a bug in the platform which is fixed, but won't make it into Firefox 20, you won't be able to use panels in your add-on if you set the package.json flag to see private windows.
<<

nagle

Posts: 188

Joined: Fri Oct 23, 2009 10:14 am

Post Fri Mar 22, 2013 3:48 pm

Re: New "private browsing" mode - how to use from page mod?

wbamberg wrote:Also note that due to a bug in the platform which is fixed, but won't make it into Firefox 20, you won't be able to use panels in your add-on if you set the package.json flag to see private windows.

That bug breaks my prefs panel. Will it be fixed before AMO starts whining that the add-on needs to be upgraded?
<<

wbamberg

Posts: 232

Joined: Thu Jun 23, 2011 4:08 pm

Post Mon Mar 25, 2013 9:11 am

Re: New "private browsing" mode - how to use from page mod?

> That bug breaks my prefs panel.
> Will it be fixed before AMO starts whining that the add-on needs to be upgraded?

1) you will have to repack for 1.14, unless we can do it for you. The current version of your add-on will be marked incompatible with Firefox 20.

2) unless you needs to see private windows, you only need to repack

3) if you do need to see private windows, and opt into seeing them, you *will not* be able to use panels in Firefox 20

4) the best advice for you, I think: for Firefox 20, repack and miss out on private windows, then update your code so it can see private windows for Firefox 21, in which your panel will work.

Return to Add-on SDK & Add-on Builder

Who is online

Users browsing this forum: No registered users

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
CA Gen2 style designed by Vjacheslav Trushkin.