开发者

How do I reliably find a request's referrer in a firefox addon?

开发者 https://www.devze.com 2023-04-05 16:33 出处:网络
I\'ve found the referrer attribute on nsIHttpChannel and this works most of the time but this is only set subject to certain security checks (e.g. it won\'t be set if you\'re navigating from an HTTPS

I've found the referrer attribute on nsIHttpChannel and this works most of the time but this is only set subject to certain security checks (e.g. it won't be set if you're navigating from an HTTPS to an HTTP URL).

I can see that it's possible to get the load context (nsILoadContext) and, through that, things like the associated window but I can't find a way of finding the referrer information through these.

So my question is this; for those requests which have a referring URL but which don't pass the security checks present on the nsI开发者_如何学JAVAHttpChannel referrer attribute, is there a way of obtaining the referrer information?


Gecko saves the referrer in the docshell.internalReferrer property even in the cases where the Referer header isn't sent. In most cases you should be able to read out referrer information like this:

if (channel instanceof nsIPropertyBag)
{
  try
  {
    referrer = channel.getProperty("docshell.internalReferrer");
  }
  catch (e)
  {
    // Internal referrer not set, fall back to the Referer header
    referrer = channel.referrer;
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消