PhantomJS and XHR Cross-domain request

1,151 views
Skip to first unread message

Finalfire

unread,
Mar 10, 2012, 5:24:48 AM3/10/12
to phan...@googlegroups.com
Hello everybody,

I'm working a little with PhantomJS: I need a stand-alone js version to automatize some batch processing.
I've some problem about using Cross-domain XHR. Following is the source I'm using:

var x = new XMLHttpRequest();

x.onreadystatechange = function() {
console.log("I'm in with status: " + x.status);
if (x.status === 200 && x.readyState === 4) {
console.log("ciao");
}
}

x.open("GET", "http://www.google.com", true);
x.send(null);

Unfortunately I receive some messages: 

undefined:0 INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable.
I'm in with status: 0 

Then execution of that file is still alive, doing anything.

Can someone explain me why there's this behavior? Apparently, I can use page.open() but I need to do a lot of operation on Document element and PhantomJS does not allow me to return document element from a page.evaluate(), plus I can't send arguments to page.evaluate() and I need it :( Maybe I'm wrong on last point but I tried everything, can't do anything.

Im running on Leopard 10.5.8, compiled Qt + PhantomJS with /deploy script.

Thanks to anyone,
F.

Finalfire

unread,
Mar 10, 2012, 6:24:40 AM3/10/12
to phan...@googlegroups.com
Cross-posting because the problem is about page.evaluate() function: I can't return anything from within evaluate. Is it normal? There's some hope to enhance it? I think it's a huge limitation, even if evaluate() is a sandboxed function.

Mike Alaimo

unread,
Mar 10, 2012, 9:32:51 AM3/10/12
to phan...@googlegroups.com

Interesting idea, use the file module to create dynamic js files.  Json encode data and then use the injectjs method of a webpage .

Ariya Hidayat

unread,
Mar 13, 2012, 1:16:57 AM3/13/12
to phan...@googlegroups.com
> Unfortunately I receive some messages:
>
> undefined:0 INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use
> an object that is not, or is no longer, usable.

That sounds like http://code.google.com/p/phantomjs/issues/detail?id=28.


--
Ariya Hidayat, http://ariya.ofilabs.com

Ariya Hidayat

unread,
Mar 13, 2012, 1:18:50 AM3/13/12
to phan...@googlegroups.com

page.evaluate can return an object just fine. See some of the
examples, find them using:

git grep '= page.evaluate'

Reply all
Reply to author
Forward
0 new messages