Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Tracium
✓ const Tracium = require('tracium');
✗ import Tracium from 'tracium';
// OR
import { Tracium } from 'tracium';
Tracium primarily exposes its API via CommonJS exports. Attempting to use ESM import syntax directly without proper Node.js CJS-ESM interop configuration or transpilation can lead to undefined module exports.
computeMainThreadTasks
✓ const Tracium = require('tracium');
const tasks = Tracium.computeMainThreadTasks(traceJSON);
✗ import { computeMainThreadTasks } from 'tracium';
The `computeMainThreadTasks` function is a method on the `Tracium` object, which is the default CommonJS export. It is not a named export and must be accessed via the imported `Tracium` object.
Demonstrates how to load a Chromium trace (using a mock JSON for direct runnability) and parse its main thread tasks, showing task type, duration, and self-time for performance analysis.
const fs = require('fs');
const Tracium = require('tracium');
// In a real application, you'd load a trace file like this:
// const traceJSON = JSON.parse(fs.readFileSync('./mytrace.json', 'utf8'));
// For demonstration, we'll create a minimal mock trace structure.
// A real Chromium trace file would be significantly larger and more complex.
const mockTraceJSON = {
'traceEvents': [
{ 'ph': 'M', 'pid': 1, 'tid': 1, 'name': 'process_name', 'args': { 'name': 'Browser' } },
{ 'ph': 'M', 'pid': 1, 'tid': 2, 'name': 'thread_name', 'args': { 'name': 'CrRendererMain' } },
{ 'ph': 'X', 'cat': 'devtools.timeline', 'name': 'ParseHTML', 'pid': 1, 'tid': 2, 'ts': 1000, 'dur': 500, 'args': {} },
{ 'ph': 'X', 'cat': 'devtools.timeline', 'name': 'EvaluateScript', 'pid': 1, 'tid': 2, 'ts': 1600, 'dur': 300, 'args': {} },
{ 'ph': 'X', 'cat': 'devtools.timeline', 'name': 'InvalidEvent', 'pid': 1, 'tid': 2, 'ts': 1900, 'dur': 100, 'args': {} }
],
'metadata': { 'clockDomain': 'timeSinceEpoch', 'numProcs': 1 }
};
const tasks = Tracium.computeMainThreadTasks(mockTraceJSON, {
// Set flatten to true to get all tasks, including child tasks, in a single array.
flatten: true,
});
console.log('Computed Main Thread Tasks:');
tasks.forEach(task => {
console.log(`- Kind: ${task.kind}, Duration: ${task.duration.toFixed(3)}ms, SelfTime: ${task.selfTime.toFixed(3)}ms`);
});
/*
Example output for the mock trace:
- Kind: parseHTML, Duration: 0.500ms, SelfTime: 0.500ms
- Kind: scriptEvaluation, Duration: 0.300ms, SelfTime: 0.300ms
- Kind: other, Duration: 0.100ms, SelfTime: 0.100ms
*/
Errors
Common errors & fixes
TypeError: Tracium is not a constructor
Attempting to instantiate `Tracium` using the `new` keyword, as if it were a class.
fixTracium exports a plain object directly, not a class. Its functions, like `computeMainThreadTasks`, should be called directly on the imported object: `Tracium.computeMainThreadTasks(...)`.
TypeError: Cannot read properties of undefined (reading 'computeMainThreadTasks') OR Tracium.computeMainThreadTasks is not a function
The `Tracium` module was not imported or required correctly, resulting in `Tracium` being `undefined` or an empty object. This commonly happens when attempting named ESM imports for a CommonJS-only package.
fixEnsure you are using the correct CommonJS `require` syntax: `const Tracium = require('tracium');`. If using ESM, you may need to rely on Node.js's CJS-ESM interop and access the default export: `import Tracium from 'tracium';` (then `Tracium.computeMainThreadTasks`). Error: Invalid traceEvents array in trace JSON
The input `traceJson` object provided to `computeMainThreadTasks` is missing the crucial `traceEvents` array, or this array is malformed or empty, which is required for a valid Chromium trace.
fixVerify that your input `traceJson` strictly conforms to the Chromium trace format, specifically that it contains a top-level `traceEvents` array populated with valid trace event objects.
Audit
Dependencies
No dependency data recorded yet.