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

Evaluate and evaluateHandle cause NPD on nil pageFunc #1543

Open
1 of 2 tasks
ankur22 opened this issue Nov 19, 2024 · 1 comment
Open
1 of 2 tasks

Evaluate and evaluateHandle cause NPD on nil pageFunc #1543

ankur22 opened this issue Nov 19, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@ankur22
Copy link
Collaborator

ankur22 commented Nov 19, 2024

Brief summary

The cause of this NPD is due to the browser module not correctly checking the arguments before trying to work with them. With JSHandle.evaluate the pageFunc argument is required, but the browser module doesn't correctly check whether it is null/undefined before working with it.

There are many other examples within the browser module where it doesn't first validate the argument before working with it (page, frame, elementHandle).

This issue can be replicated with:

import { browser } from 'k6/browser';

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

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

  try {
    await page.goto('https://test.k6.io/my_messages.php');

    const jsHandle = await page.waitForSelector('input[name="login"]');
    // This is incorrect, the pageFunction arg is required on evaluate and this is
    // why we get a NPD since we don't check it is nil first.
    await jsHandle.evaluate();
  } finally {
    await page.close();
  }
}

There's also an issue with waitForSelector -- it returns an ElementHandle, but it is mapped to a JSHandle 🤔

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x1606eea]

goroutine 1536 [running]:
github.com/grafana/xk6-browser/browser.mapJSHandle.func3.1()
github.com/grafana/[email protected]/browser/js_handle_mapping.go:27 +0x16a
github.com/grafana/xk6-browser/k6ext.promise.func1()
github.com/grafana/[email protected]/k6ext/promise.go:24 +0x2c
created by github.com/grafana/xk6-browser/k6ext.promise in goroutine 53
github.com/grafana/[email protected]/k6ext/promise.go:23 +0x9a

test run: 3526237

xk6-browser version

v1.9.1

Tasks

  1. mapping
    inancgumus
@inancgumus
Copy link
Member

inancgumus commented Nov 19, 2024

Thanks for the explanation, a fix is here.

@inancgumus inancgumus self-assigned this Nov 19, 2024
@ankur22 ankur22 changed the title mapJSHandle invalid memory address or nil pointer dereference Evaluate and evaluateHandle cause NPD on nil pageFunc Nov 21, 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

2 participants