In a firefox add-on, I would like to send an HTTPRequest to the URL of the button in this website: www.google.com/ads/preferences. What I try to do is to get the form that contains the button and make an HTTP request to the action attribute (the goal is to get doubleclick cookies that the server sends if you do that). The problem is that when I get the form I get an XRayWrapper and I don't know how to retrieve that attribute (I've already tried to do:
// unwrap is not available on older branches (3.5 and 3.6) - Bug 533596
if (XPCNativeWrapper && "unwrap" in XPCNativeWrapper) {
try {
return XPCNativeWrapper.unwrap(thing);
} catch(e) {
// Unwrapping will fail for JS literals - numbers, for example. Catch
// the exception and proceed, it will eventually be returend as-is.
}
}
if (thing['wrappedJSObject']) {
return thing.wrappedJSObject;
}
Also, I've found that when I get the div with id="content-pane" that contains the form and access to the innerHTML, I get an empty string. But It must be possible because I can view these contents with firebug, which is another add-on....
I'm really lost, thanks for your help!
EDIT: I'm using the add-on SDK, so I created a page worker to handle all this:
createDoubleClick: function() {
new PageWorker.Page({
contentURL: "http://www.google.com/ads/preferences",
contentScriptFile: data.url('contentScripts/getCookie.js'),
contentScriptWhen: "end",
onMessage: function(message) {
console.log(message);
}
});
}
Then, in the contetScript I try to get the DOM:
// Get button
var idPanel = "content-pane";
// Get content panel
var panel = document.getElementById(idPanel);
console.log(panel.innerHTML);
Result:
info:
The only scenario where you would want to remove that wrapper would be an extension that wants to interact with the JavaScript code of a web page - and even then it is doubtful whether you should do it. In this particular scenario you definitely shouldn't do it. XrayWrapper (formerly known as XPCNativeWrapper) is a security layer meant to protect your extension. You can still access any DOM methods and attributes through it, just as you would do it normally:
var url = form.getAttribute("action");
If this call doesn't return anything then most likely the action
attribute simply isn't set when you are trying to access it. You might need to wait longer, e.g. run your code in the load
event handler rather than DOMContentLoaded
(obviously, I don't know what you are currently doing).