Skip to content

[REGRESSION]: page.evaluate with a string no longer works unless wrapped in an IIFE #10819

@trusktr

Description

@trusktr

Context:

  • GOOD Playwright Version: [what Playwright version worked nicely?] 1.8
  • BAD Playwright Version: [what Playwright version doesn't work any more?] 1.17
  • Operating System: [e.g. Windows, Linux or Mac] Ubuntu
  • Extra: [any specific details about your environment]

Code Snippet

    function add(...addends) {
      return addends.reduce(
        (accumulator, currentValue) => accumulator + currentValue
      );
    }

    const functionResult = await page.evaluate(`
      ${add.toString()}
      var result = add(1, 2, 3);
      Promise.resolve(result);
    `);

Describe the bug

I get the error:

    page.evaluate: SyntaxError: Unexpected token 'var'

I am trying to migrate from an older jest-playwright-preset setup to @playwright/test, in the process updating playwright. This code worked before.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy