Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

() => ({ window, document }) results in Unexpected end of input #1381

Open
ankur22 opened this issue Jun 11, 2024 · 0 comments
Open

() => ({ window, document }) results in Unexpected end of input #1381

ankur22 opened this issue Jun 11, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ankur22
Copy link
Collaborator

ankur22 commented Jun 11, 2024

Brief summary

It seems that the way k6 browser parses the functions in jshandle.evaluateHandle isn't compatible with expected javascript syntax.

xk6-browser version

NA

OS

NA

Chrome version

NA

Docker version and image (if applicable)

NA

Steps to reproduce the problem

When running the following test:

import { browser } from 'k6/experimental/browser';

export const options = {
  scenarios: {
    browser: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
};

export default async function () {
  const page = await browser.newPage();

  try{
    await page.goto('https://test.k6.io/browser.php');
    const jsHandle = await page.evaluateHandle(() => ({ window, document }));

    const properties = await jsHandle.getProperties();
    console.log(JSON.stringify(properties)); // {"window":{},"document":{}}
  } finally {
    await page.close();
  }
}

The result is Uncaught (in promise) evaluating handle for page: evaluating handle for frame: SyntaxError: Unexpected end of input.

If the page.evaluateHandle is replaced with:

    const jsHandle = await page.evaluateHandle(() => {
      return { window, document };
    });

Then it works as expected.

Expected behaviour

Logs to console: {"document":{},"window":{}}.

Actual behaviour

Errors with Uncaught (in promise) evaluating handle for page: evaluating handle for frame: SyntaxError: Unexpected end of input.

@ankur22 ankur22 added the bug Something isn't working label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant