I have a weird bug in my addon, the addon itself needs to add a request header parameters for a specific domain, it's all working, but the bug is, that the observer http-on-modify-request is not called at start, only if I reload the page, then it's working.
I mean:
- I go to mysite.com/ - no header modified,
- I reload page - header modefied
- reload again - header modefied
- new tab at mysite.com/ - no header modified
- reload tab - header modefied
My code, I'm using the addon sdk:
exports.main = function(options,callbacks) {
// Create observer
httpRequestObserver =
{
observe: function(subject, topic, data)
{
if (topic == "http-on-modify-request") {
//only identify to specific preference domain
var windowsService = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);
var uri = windowsService.getMostRecentWindow('navigator:browser').getBrowser().currentURI;
var domainloc = uri.host;
if (domainloc=="mysite.com"){
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
httpChannel.setRequestHeader("x-test", "test", false);
}
}
},
register: function()
{
var observerService = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
observerService.addObserver(this, "http-on-modify-request", false);
},
unregister: function()
{
var observerService = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
observerService.removeObserver(this, "http-on-modify-request");
}
};
//register observer
httpRequestObserver.register();
};
exports.onUnload = function(reason) {
httpRequestObserver.unregister();
};
Please help me, I searched for hours with no results. The code is working, but not at first time of page loading, only if I reload.
The goal is that only on mysite.com, there will be a x-text=test
header request, all the time, but only on mysite.com.