Skip to content

htmlReport Throws TypeError When Appending Custom Content #4702

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

Open
critboy-92 opened this issue Apr 17, 2025 · 0 comments
Open

htmlReport Throws TypeError When Appending Custom Content #4702

critboy-92 opened this issue Apr 17, 2025 · 0 comments
Assignees

Comments

@critboy-92
Copy link

Brief summary

When using the official htmlReport from k6/html to generate a report and appending custom HTML content (e.g., a table of abnormal requests), a TypeError: Value is not an object: undefined is thrown. Switching to the third-party k6-reporter module resolves the issue, suggesting a potential bug or limitation in the official htmlReport implementation.

k6 version

v0.58

OS

Windows 10

Docker version and image (if applicable)

No response

Steps to reproduce the problem

Steps to reproduce the problem

  1. Create a k6 script that generates some metrics and logs abnormal requests (e.g., requests with duration > 1000ms).

  2. In the handleSummary function, use the official htmlReport to generate a default report:

import { htmlReport } from 'k6/html';
export function handleSummary(data) {
const defaultReport = htmlReport(data, { title: "WEB Test Report" });
const customContent = "

Custom Section

Test

";
const bodyEndIndex = defaultReport.lastIndexOf('');
const modifiedReport = defaultReport.slice(0, bodyEndIndex) + customContent + defaultReport.slice(bodyEndIndex);
return { 'report.html': modifiedReport };
}

  1. Run the script with the k6_web_dashboard option

  2. Observe the error in the console output.

Expected behaviour

The htmlReport function should generate a report, and appending custom HTML content (e.g., a table) to the report should not throw an error. The final report should include both the default metrics generated by htmlReport and the custom content.

Actual behaviour

When appending custom content to the report generated by htmlReport, the following error is thrown:

TypeError: Value is not an object: undefined

The error occurs during the execution of htmlReport(data, { title: "WEB Test Report" }) or when modifying the report string. However, if I switch to the third-party k6-reporter module by changing the import to:

import { htmlReport } from 'https://raw.githubusercontent.com/benc-uk/k6-reporter/main/dist/bundle.js';

the error no longer occurs, and the custom content is successfully appended to the report.

Additional Notes

The data object passed to htmlReport is valid and contains expected fields like metrics, state, and root_group (I can provide the full data log if needed).

The issue might be related to how the official htmlReport handles the Web Dashboard data or its internal HTML structure, as the third-party k6-reporter does not exhibit this problem.

I suspect the official htmlReport may not support appending custom content to its generated report, or there might be a bug in its implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants