0

I have this working code (puppeteer) : 

async function extractedEvaluateCall(page) {
    await page.waitForXPath(xpath);
    const links = await page.$x(xpath);
    const results = await page.evaluate((...links) => {
      return links.map(e => e.innerText);
    }, ...links);
}

What does the notation ... does here ?

I tried without, it doesn't work:

UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON Are you passing a nested JSHandle?

links is already an array, why the need of spread operator ?

MevatlaveKraspek
  • 2,246
  • 3
  • 20
  • 23
  • 1
    `links` is already an array, why the need of spread operator ? – MevatlaveKraspek May 21 '21 at 22:51
  • 1
    It’ll destructure the array and pass the values as separate arguments to the function. – fubar May 22 '21 at 06:11
  • 2
    The first one is [Rest parameters syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) and the second one is [Spread syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax)? – adiga May 22 '21 at 06:12
  • @fubar there is no destructuring here. One is rest syntax and the other is spread syntax. – adiga May 22 '21 at 06:14

0 Answers0