grafana / xk6-browser

k6 extension that adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol
https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/browser/
GNU Affero General Public License v3.0
337 stars 42 forks source link

Runtime error with extraHTTPHeaders #111

Closed kj187 closed 2 years ago

kj187 commented 2 years ago

If I add extra HTTP headers, I got a runtime error invalid memory address or nil pointer dereference

Used version: k6 v0.34.1 ((devel), go1.17.2, darwin/amd64)

Used script:

import { sleep } from 'k6';
import launcher from "k6/x/browser";

export default function () {

    const browser = launcher.launch('chromium', {
        headless: false,
        slowMow: '1500ms'  // slow down by 500ms
    });
    const context = browser.newContext({
        extraHTTPHeaders: {
            "X-Access-Token": "myvalue"
        },
    });

    const page = context.newPage();

    page.goto('https://www.google.de', { waitUntil: 'load' });

    sleep(3)
    page.screenshot({ path: `screenshots/homepage.png`,  });

    page.close()
    browser.close()

}

I also tried it with

        extraHTTPHeaders: {
            name: "myvalue"
        },

Whole stack trace:

ERRO[0001] panic: runtime error: invalid memory address or nil pointer dereference
goroutine 72 [running]:
runtime/debug.Stack()
    runtime/debug/stack.go:24 +0x65
go.k6.io/k6/js.(*VU).runFn.func1()
    go.k6.io/k6@v0.34.2-0.20211105090803-dae70006ca77/js/runner.go:749 +0x134
panic({0x1d692a0, 0x2d277f0})
    runtime/panic.go:1038 +0x215
github.com/dop251/goja.AssertFunction.func1.1()
    github.com/dop251/goja@v0.0.0-20211022113120-dc8c55024d06/runtime.go:2162 +0x74
panic({0x1d692a0, 0x2d277f0})
    runtime/panic.go:1038 +0x215
github.com/dop251/goja.(*vm).try.func1()
    github.com/dop251/goja@v0.0.0-20211022113120-dc8c55024d06/vm.go:512 +0x8eb
panic({0x1d692a0, 0x2d277f0})
    runtime/panic.go:1038 +0x215
github.com/grafana/xk6-browser/common.(*BrowserContextOptions).Parse(0xc00249a0d0, {0x219f5a8, 0xc0023ea750}, {0x21be838, 0xc002462bd0})
    github.com/grafana/xk6-browser@v0.0.0-00010101000000-000000000000/common/browser_context_options.go:103 +0xf1d
github.com/grafana/xk6-browser/common.(*Browser).NewContext(0xc000556000, {0x21be838, 0xc002462bd0})
    github.com/grafana/xk6-browser@v0.0.0-00010101000000-000000000000/common/browser.go:358 +0x3a5
reflect.Value.call({0x1d1e520, 0xc000fae880, 0x3540f18}, {0x1efcf9c, 0x4}, {0xc00080ef60, 0x1, 0xc002363290})
    reflect/value.go:543 +0x814
reflect.Value.Call({0x1d1e520, 0xc000fae880, 0xc002462bd0}, {0xc00080ef60, 0x1, 0x1})
    reflect/value.go:339 +0xc5
github.com/dop251/goja.(*Runtime).wrapReflectFunc.func1({{0x21be838, 0xc002462810}, {0xc002a90160, 0x1, 0x6}})
    github.com/dop251/goja@v0.0.0-20211022113120-dc8c55024d06/runtime.go:1757 +0x259
github.com/dop251/goja.(*vm)._nativeCall(0xc0013da100, 0xc0023e4e60, 0x1)
    github.com/dop251/goja@v0.0.0-20211022113120-dc8c55024d06/vm.go:2658 +0x223
github.com/dop251/goja.call.exec(0x10, 0xc0013da100)
    github.com/dop251/goja@v0.0.0-20211022113120-dc8c55024d06/vm.go:2630 +0x81b
github.com/dop251/goja.(*vm).run(0xc0013da100)
    github.com/dop251/goja@v0.0.0-20211022113120-dc8c55024d06/vm.go:402 +0x8b
github.com/dop251/goja.(*baseJsFuncObject)._call(0xc00230e160, {{0x21bf088, 0x2d77300}, {0xc00239b5e0, 0x1, 0x1}}, {0x0, 0x0}, {0x21bf088, 0x2d77300})
    github.com/dop251/goja@v0.0.0-20211022113120-dc8c55024d06/func.go:172 +0x2d8
github.com/dop251/goja.(*funcObject).call(...)
    github.com/dop251/goja@v0.0.0-20211022113120-dc8c55024d06/func.go:180
github.com/dop251/goja.(*funcObject).Call(0xc0016db860, {{0x21bf088, 0x2d77300}, {0xc00239b5e0, 0x1, 0x1}})
    github.com/dop251/goja@v0.0.0-20211022113120-dc8c55024d06/func.go:140 +0xc9
github.com/dop251/goja.AssertFunction.func1.2()
    github.com/dop251/goja@v0.0.0-20211022113120-dc8c55024d06/runtime.go:2167 +0x7d
github.com/dop251/goja.(*vm).try(0x10637c2, 0x1051e46)
    github.com/dop251/goja@v0.0.0-20211022113120-dc8c55024d06/vm.go:518 +0x1a4
github.com/dop251/goja.AssertFunction.func1({0x21bf088, 0x2d77300}, {0xc00239b5e0, 0xc0016db938, 0x0})
    github.com/dop251/goja@v0.0.0-20211022113120-dc8c55024d06/runtime.go:2166 +0x110
go.k6.io/k6/js.(*VU).runFn(0xc002320320, {0x219f5a8, 0xc0023ea300}, 0x60, 0xc00080e4f8, {0xc00239b5e0, 0x1, 0x1})
    go.k6.io/k6@v0.34.2-0.20211105090803-dae70006ca77/js/runner.go:754 +0x27c
go.k6.io/k6/js.(*ActiveVU).RunOnce(0xc000fae300)
    go.k6.io/k6@v0.34.2-0.20211105090803-dae70006ca77/js/runner.go:705 +0x37b
go.k6.io/k6/lib/executor.getIterationRunner.func1({0x219f5a8, 0xc0023ea060}, {0x21832e0, 0xc000fae300})
    go.k6.io/k6@v0.34.2-0.20211105090803-dae70006ca77/lib/executor/helpers.go:88 +0x64
go.k6.io/k6/lib/executor.PerVUIterations.Run.func3({0x2195300, 0xc002320320})
    go.k6.io/k6@v0.34.2-0.20211105090803-dae70006ca77/lib/executor/per_vu_iterations.go:239 +0x40a
created by go.k6.io/k6/lib/executor.PerVUIterations.Run
    go.k6.io/k6@v0.34.2-0.20211105090803-dae70006ca77/lib/executor/per_vu_iterations.go:252 +0xbdb

Goja stack:
native
ERRO[0001] a panic occurred in VU code but was caught: runtime error: invalid memory address or nil pointer dereference  executor=per-vu-iterations scenario=default
imiric commented 2 years ago

Hi, thanks for reporting this! It's definitely a bug. We'll try to get it fixed ASAP, and possibly do a patch release soon.

imiric commented 2 years ago

Hi @kj187, this should be fixed now. You can build the binary yourself with xk6 build --with github.com/grafana/xk6-browser@main or wait a few days until we make a patch release.