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/xk6-browser@v1.9.1/browser/js_handle_mapping.go:27 +0x16a
github.com/grafana/xk6-browser/k6ext.promise.func1()
github.com/grafana/xk6-browser@v1.9.1/k6ext/promise.go:24 +0x2c
created by github.com/grafana/xk6-browser/k6ext.promise in goroutine 53
github.com/grafana/xk6-browser@v1.9.1/k6ext/promise.go:23 +0x9a
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
thepageFunc
argument is required, but the browser module doesn't correctly check whether it isnull
/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:
There's also an issue with
waitForSelector
-- it returns anElementHandle
, but it is mapped to aJSHandle
🤔test run: 3526237
xk6-browser version
v1.9.1