Code Monkey home page Code Monkey logo

node-phantom-promise's People

Contributors

foray1010 avatar greenkeeper[bot] avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-phantom-promise's Issues

Direct assignment of page.onWhatever functions is broken.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.