What is har-validator?
The har-validator npm package is a library designed to validate HTTP Archive (HAR) files. HAR files are JSON-formatted archives that track all the logging of a web browser's interaction with a site. This package ensures that HAR files adhere to the specification and structure expected, making it useful for developers working with web performance and debugging, API testing, and network monitoring.
HAR file validation
This feature allows developers to validate HAR files against the HAR format specification. The code sample demonstrates how to use the har-validator package to validate a HAR file. If the file is valid, it logs a success message; otherwise, it catches and logs the validation error.
const HARValidator = require('har-validator');
async function validateHAR(harData) {
try {
const valid = await HARValidator.har(harData);
console.log('HAR is valid:', valid);
} catch (err) {
console.error('HAR validation error:', err.message);
}
}