Params
Note
A module with a better and standard API exists.
The new k6/experimental/websockets API partially implements the WebSockets API living standard.
When possible, we recommend using the new API. It uses a global event loop for consistency with other k6 APIs and better performance.
Params is an object used by the WebSocket methods that generate WebSocket requests. Params contains request-specific options like headers that should be inserted into the request.
Example of custom metadata headers and tags
A k6 script that will make a WebSocket request with a custom header and tag results data with a specific tag
import ws from 'k6/ws';
export default function () {
const url = 'ws://echo.websocket.org';
const params = {
headers: { 'X-MyHeader': 'k6test' },
tags: { k6test: 'yes' },
};
const res = ws.connect(url, params, function (socket) {
socket.on('open', function () {
console.log('WebSocket connection established!');
socket.close();
});
});
}