Closed belaviyo closed 8 years ago
aContext The nsIDOMNode or nsIDOMWindow that initiated the request, or something that can QueryInterface() to one of those; can be null if inapplicable.
May be aTopFrameElement
refers to topmost browser window, that is actually non-private.
You can try something like
if(
aTopFrameElement instanceof Ci.nsIDOMChromeWindow
&& "gBrowser" in aTopFrameElement
) {
var gBrowser = aTopFrameElement.gBrowser;
var contentWindow = gBrowser.contentWindow || gBrowser.contentWindowAsCPOW;
console.error(isPrivate(contentWindow));
}
Also may be it's possible to ask aRequestOrigin
about Ci.nsILoadContext
.
Something like
aRequestOrigin.loadGroup.notificationCallbacks
.getInterface(Ci.nsILoadContext);
And then use nsILoadContext.usePrivateBrowsing
.
It turned out aTopFrameElement
is the actual XUL browser element. So I needed to dive into aTopFrameElement.contentWindow
and then the isPrivate
can detect the privacy context just fine.
Thanks for the help.
I am using nsISimpleContentPolicy to block some network resources in my extension.
If I open a private window, the
isPrivate(aTopFrameElement)
returnstrue
for all requests initiated from the private window as theaTopFrameElement
is in the context of the private mode. However, if requests are from a private tab,isPrivate(aTopFrameElement)
returnsfalse
.Any idea how to fix this?