foray1010 / node-phantom-promise Goto Github PK
View Code? Open in Web Editor NEWA simple wrapper for baudehlo/node-phantom-simple with promise
License: MIT License
A simple wrapper for baudehlo/node-phantom-simple with promise
License: MIT License
First of all, thanks for node-phantom-promise
. I like the notion of returning thenables rather than passing callbacks around as it makes for cleaner code.
Unfortunately, it looks like your wrapper breaks one important thing, which is that setting functions to page.onConsoleMessage
, page.onCallback
, etc., no longer works.
Assume a PhantomJS page under the variable page
, opened using the standard pattern:
phantom.create({path: require('phantomjs').path}).then((engine) => {
engine.createPage().then((page) => {
...
});
});
I should be able to set certain properties to page
directly:
page.onConsoleMessage = (msg, lineno, src) => {
console.log(msg);
};
And then it should work:
// This should log out 'foo' and 'bar', possibly in the reverse order.
page.evaluate(function() {
console.log('foo');
return 'bar';
}).then((result) => console.log(result));
It doesn't, though. The onConsoleMessage
function never fires. It does in node-phantom-simple
, though, so something with the wrapper is breaking it.
You can get around this, kind of, by using setFn
, which still works under the wrapper:
page.setFn('onConsoleMessage', function(msg) { console.log(msg) }).then(() => {
page.evaluate(function() {
console.log('foo');
return 'bar';
}).then((result) => console.log(result));
});
But this is an insufficient workaround because setFn
(in node-phantom-simple
, not in your code) actually converts the function to a string and then runs it through eval
, meaning that all function context is lost (this makes baby moogle cry, kupo!).
Anyway, it would be awesome if direct assignment of page.onWhatever = function () { ... }
worked again. I think it needs to be some sort of exemption in promisifyAll
but I wasn't certain enough to put together a pull request.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.