This is documentation for the next version of K6. For the latest stable release, go to the latest version.
Params
Params
is an object used by the WebSocket constructor. The Params
object contains request-specific options, such as headers that should be inserted into the connection initialization request.
Example of custom metadata headers and tags
A k6 script that makes a WebSocket request with a custom header and tags results data with a specific tag
import { WebSocket } from 'k6/experimental/websockets';
export default function () {
const url = 'ws://localhost:10000';
const params = {
headers: { 'X-MyHeader': 'k6test' },
tags: { k6test: 'yes' },
};
const ws = new WebSocket(url, null, params);
ws.onopen = () => {
console.log('WebSocket connection established!');
ws.close();
};
}
The preceding example uses a WebSocket echo server, which you can run with the following command:
$ docker run --detach --rm --name ws-echo-server -p 10000:8080 jmalloc/echo-server