peerigon / phridge

A bridge between node and PhantomJS
The Unlicense
519 stars 50 forks source link

Can I pass page to run method? #28

Closed alexpts closed 9 years ago

alexpts commented 9 years ago
var page;

phantomNode.run({}, function(result, resolve) {
    var page = webpage.create();
    result['page'] = page;

    page.open("https://google.com", function() {
        result['title'] = page.evaluate(function() {
            return document.querySelector('title').innerText;
        });

        resolve(result)
    });
}).then(function(result) {
    page = result['page'];
   ...
});

phantomNode.run({}, page, function(result, page, resolve) {
    page.open("https://google.com", function() {
        result['title'] = page.evaluate(function() {
            return document.querySelector('title').innerText;
        });

        resolve(result)
    });
}).then(function(result) {
    ...
});

How I can pass page for reuse wrong? ... I use global variable now, but I think it is wrong.

jhnns commented 9 years ago

No I'm sorry, that's not possible because page can't be stringified by JSON.stringify(). The page object "lives" in a completely different process.

I've improved the note on returning only JSON-valid objects.

jhnns commented 9 years ago

Extract the results from page and return that object only.

alexpts commented 9 years ago

Ok, thanks.