OnetapInc / chromy

Chromy is a library for operating headless chrome. 🍺🍺🍺
MIT License
605 stars 41 forks source link

evaluate(func, args) does not seem to allow functions to be passed #95

Open disophisis opened 6 years ago

disophisis commented 6 years ago

I've copied a client side script from protractor (waitforangular) and I am attempting to use it with chromy.

Here's a small snippet ( I don't know that the entire code is required)

let waitForAngular = function (rootSelector, callback) {
        console.log(callback);
        console.log(rootSelector);
        try {
            // Wait for both angular1 testability and angular2 testability.

            var testCallback = callback;

            // Wait for angular1 testability first and run waitForAngular2 as a callback
            var waitForAngular1 = function (callback) {

                if (window.angular) {

I call:

chromy.evaluate(waitForAngular, ['app-root', callback]));

in the case of this snippet, callback is an anonymous function that was declared earlier on.

callback seems to be converted to a boolean value by doing this. If I look at the output from the console log statements from the waitForAngular call, 'app-root' gets passed correctly and the callback will either be undefined or true.

Is there a way to pass a callback function to the waitForAngular function using evaluate?

TechQuery commented 6 years ago

Chromy.prototype.evaluate() returns a Promise() object, so you can use Promise.prototype.then() or await keyword in ECMAScript 8.