Reputation: 1142
I defined a http-on-modify-request
observer in Mozilla's Addon Builder, and want to redirect requests (change subject.URI.spec
), but Firefox complains about:
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]
Why doesn't it work?
Maybe I can't use the http-on-modify-request
observer to rewrite URIs?
How do I do that?
Upvotes: 3
Views: 2274
Reputation: 32063
Yes, nsIChannel docs say "The URI corresponding to the channel. Its value is immutable. Read only." And the immutable check seems to indeed return NS_ERROR_ABORT (source).
Unfortunately for you, this guy ( Redirecting Request (nsiHttpChannel?) in Firefox Extensions ) didn't post the solution he found, also this question is asked here and here on mozillazine.
The best idea I have is too much work for this: to try nsITraceableChannel. Wladimir here has an idea to "make all the necessary calls to nsIChannel.notificationCallbacks and cancel the request after that". Bug 286159 has some discussion on this (there didn't seem to be a way to do this cleanly in 2005).
Since this is a recurring question, it would be great if you got a confirmation from a Necko peer, then documented it on MDC.
Upvotes: 3