Skip to content

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

Closed
@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