B
B
babbert2019-03-14 18:56:16
JavaScript
babbert, 2019-03-14 18:56:16

How to pass a variable to page.evaluate?

An example that works:

five = 5
page.evaluate(function(val) {
        return val;
},five).then(function(num){
        console.log(num)
});

But I need to specify an already existing function in page.evaluate . How can I pass a variable to it?
five = 5
page.evaluate(test(five),five).then(function(num){
        console.log(num)
});

function test(num) {
        return num;
}

It doesn't work anymore

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RAX7, 2019-03-14
@babbert

page.evaluate(test, five).then(function(num) {
    console.log(num)
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question