在Mozilla Addon Builder中重定向http请求URI

时间:2011-12-11 13:01:19

标签: javascript firefox firefox-addon mozilla firefox-addon-sdk

我在Mozilla的Addon Builder中定义了一个http-on-modify-request观察者,并希望重定向请求(更改subject.URI.spec),但Firefox抱怨:

Error: An exception occurred.
Traceback (most recent call last):
  File "http://chrome.angrybirds.com/", line 2536, in null
  File "http://chrome.angrybirds.com/", line 2344, in null
  File "http://chrome.angrybirds.com/", line 2988, in wi
  File "http://chrome.angrybirds.com/", line 1756, in ti
  File "http://chrome.angrybirds.com/", line 1231, in Ji
  File "http://chrome.angrybirds.com/", line 3366, in Ri
  File "http://chrome.angrybirds.com/", line 2381, in Di
  File "http://chrome.angrybirds.com/", line 2956, in Ni
  File "http://chrome.angrybirds.com/", line 3366, in DHb
  File "http://chrome.angrybirds.com/", line 3340, in oHb
  File "http://chrome.angrybirds.com/", line 1869, in Eic
  File "http://chrome.angrybirds.com/", line 3285, in BS
  File "http://chrome.angrybirds.com/", line 3362, in _Jb
  File "http://chrome.angrybirds.com/", line 3054, in _Bb
  File "http://chrome.angrybirds.com/", line 2020, in dJb
  File "http://chrome.angrybirds.com/", line 2889, in fJb
  File "resource://jid0-[snipped id]-api-utils-lib/observer-service.js", line 176, in null
    this.callback(subject, data);
  File "resource://jid0-[snipped id]-moddedbirds-url-rewriter-lib/main.js", line 11, in null
    if(endsWith(s.URI.spec,search)) s.URI.spec=replace;
[Exception... "Component returned failure code: 0x80004004 (NS_ERROR_ABORT)
  [nsIURI.spec]"  nsresult: "0x80004004 (NS_ERROR_ABORT)" location: "JS frame
  :: resource://jid0-[snipped id]-api-utils-lib/securable-module.js
  -> resource://jid0-[snipped id]-moddedbirds-url-rewriter-lib/main.js ::
  <TOP_LEVEL> :: line 11"  data: no]

为什么不起作用?

也许我不能使用http-on-modify-request观察者来重写URI?

我该怎么做?

1 个答案:

答案 0 :(得分:3)

是的,nsIChannel docs说“与频道对应的URI。它的值是不可变的。只读。”并且不可变检查似乎确实返回NS_ERROR_ABORT(source)。

不幸的是,这个人(Redirecting Request (nsiHttpChannel?) in Firefox Extensions)没有发布他找到的解决方案,这个问题也被问到herehere关于mozillazine。

我最好的想法是做太多工作:尝试nsITraceableChannel。 Wladimir here有一个想法是“对nsIChannel.notificationCallbacks进行所有必要的调用并在此之后取消请求”。 Bug 286159对此进行了一些讨论(2005年似乎没有办法干净利落地做到这一点。)

由于这是一个反复出现的问题,如果您从Necko peer获得确认,然后将其记录在MDC上,那就太棒了。