Anonymous Panel?

How do I make the Panel stay anonymous?
I want to enable my translation add-on for private windows, but when I’m opening a panel with an external website, that website still gets all the cookies from the main browser. How do I disable that?
for xmlhttprequest, there is the option mozAnon, which works nicely for xhr, but is there something like that for Panel?

1 Like

I’m not sure about how to do it with the SDK.

But if no one for the sdk shows up, you can grab the XUL element of it with getActiveView and then set the properties on the iframe/browser of disablehistory -

https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/browser

And then you would do all your page loads with loadURIWithFlags with the anonymous flag:

https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/browser#m-loadURIWithFlags

https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XUL/Method/loadURIWithFlags

So here is a bit of an example:

let myPanel = …({

})

let { getActiveView }=require(“sdk/view/core”);
let myPanelView = getActiveView(myPanel);

myPanelView.setAttribute(‘blah’, ‘blah’);

myPanelView.loadURIWithFlags(… Ci.nsIWebNavigation.FLAG HERE

I just looked at the docs and cant find that anonymous flag. I think I was mixing it up with Ci.nsIRequest.LOAD_ANONYMOUS

But you should be able to use LOAD_ANONYMOUS with loadURI the exact code or way is escaping me right now, try some searching on github along these lines. https://github.com/search?l=javascript&q=loadURIWithFlags+ANONYMOUS&ref=searchresults&type=Code&utf8=✓

1 Like

Thanks. That helped a lot!
It seems like I don’t need the loadUriWithFlags.

I had to set contentURL initially to about:blank tho, as the attribute was not set at the time, rendering it useless on first load.
This is the working code:

var myPanel = panel.Panel({ 
    width: w,
    height: h,
    contentURL: 'about:blank'
});
var view = core.getActiveView(myPanel);
view.setAttribute("disablehistory", true);
myPanel.show();
myPanel.contentURL = url;
1 Like

Awesome! Thanks for sharing the solution!