rlr / dotjs-addon

[unmaintained] ~/.js for Firefox
BSD 3-Clause "New" or "Revised" License
144 stars 17 forks source link

Incorrect document element #8

Closed djl closed 13 years ago

djl commented 13 years ago

While jumping between Chrome and Firefox I noticed that some custom JS scripts I run were not working correctly in Firefox.

Turns out the document element isn't actually a real document object. Instead of returning the expected HTMLDocument object, it returns [object XrayWrapper [object HTMLDocument]].

Is there any way to have document refer to the real HTMLDocument object?

rlr commented 13 years ago

I noticed this weirdness too but was hoping everything would just work... I guess not. Can you provide a minimal snippet of code that fails due to this so I can try a few things out? Thanks.

djl commented 13 years ago

Sure. Here's the snippet that tipped me off:

document.onkeydown = null;
rlr commented 13 years ago

Strange thing is if I just do alert(document); it shows [object HTMLDocument] :-/

rlr commented 13 years ago

This also works:

document.onclick = function() {
    alert('click');
}

(I am on version 0.9 which just got approved yesterday)

djl commented 13 years ago

Well I'm lost. I'm also on 0.9 and doing alert(document); shows this for every page:

broke

I'll keep looking into what's going on. It'll probably be a problem on my side.

rlr commented 13 years ago

oh now that is really weird :(

oh wait, what version of Firefox are you on? Mac?

rlr commented 13 years ago

Oooh, I do get that with Firefox 5... I was testing on Aurora... INTERESTING!

djl commented 13 years ago

I'm on Firefox 5.0.1, OS X.

Aha! It doesn't happen on Aurora. Maybe it was an upstream problem?

Ninja edit: you're too quick for me!

yvesvanbroekhoven commented 13 years ago

Hi guys,

I have the same problem with FF 5 on Mac with the following snippet:

$("select").change(function(){
  window.location  = "http://google.com"
});

I also get the XrayWrapper object instead of the normal:

Alt text

Any ideas how to fix this?

rlr commented 13 years ago

I experimented a little but wasn't able to get the object out of the wrapper. I'll try to find help.

hablutzel1 commented 13 years ago

It unwraps and exposes the real object

var realObject= XPCNativeWrapper.unwrap(wrappedObject);

rlr commented 13 years ago

Thanks @skarootz, I'll give that a try!

rlr commented 13 years ago

@skarootz That doesn't seem to be working for me.

alert(document);
alert(XPCNativeWrapper.unwrap(document));

shows [object XrayWrapper [object HTMLDocument]] in both cases :(

hablutzel1 commented 13 years ago

Not sure about the reason, I found that solution when I was trying to access a DOM Object from a greasemonkey script (firefox 4).

On Fri, Jul 22, 2011 at 8:44 AM, rlr < reply@reply.github.com>wrote:

@skarootz That doesn't seem to be working for me.

alert(document);
alert(XPCNativeWrapper.unwrap(document));

shows [object XrayWrapper [object HTMLDocument]] in both cases :(

Reply to this email directly or view it on GitHub: https://github.com/rlr/dotjs-addon/issues/8#issuecomment-1631788

Jaime Hablutzel - 9-9956-3299

(tildes omitidas intencionalmente)

yvesvanbroekhoven commented 13 years ago

Hi guys,

I have found documentation about this on https://developer.mozilla.org/en/XPCNativeWrapper.

Now, I got console.log working in a quick example, needs to be wrapped in a check of course

// Normally, you can access console.log just like this
window.console.log("this should not work");

// But now we need a work around
_window = new XPCNativeWrapper(content, "window");
_window = _window.wrappedJSObject
_window.console.log("this should work");
_window.console.log(_window.location.hostname);

Hope we can narrow this down to a fix :)

rlr commented 13 years ago

Yay, thanks @yvesvanbroekhoven! I think that fixes it ^^