{"id":13451976,"url":"https://github.com/paulirish/devtools-timeline-model","last_synced_at":"2025-04-04T10:06:48.395Z","repository":{"id":57101786,"uuid":"52418769","full_name":"paulirish/devtools-timeline-model","owner":"paulirish","description":"Unsupported","archived":false,"fork":false,"pushed_at":"2022-11-02T10:27:41.000Z","size":4776,"stargazers_count":176,"open_issues_count":15,"forks_count":35,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-01T02:37:35.792Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paulirish.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-24T06:07:39.000Z","updated_at":"2025-02-11T03:04:28.000Z","dependencies_parsed_at":"2023-01-21T04:19:21.496Z","dependency_job_id":null,"html_url":"https://github.com/paulirish/devtools-timeline-model","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulirish%2Fdevtools-timeline-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulirish%2Fdevtools-timeline-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulirish%2Fdevtools-timeline-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulirish%2Fdevtools-timeline-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paulirish","download_url":"https://codeload.github.com/paulirish/devtools-timeline-model/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247157046,"owners_count":20893202,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T07:01:08.934Z","updated_at":"2025-04-04T10:06:48.366Z","avatar_url":"https://github.com/paulirish.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# devtools-timeline-model [![Build Status](https://travis-ci.org/paulirish/devtools-timeline-model.svg?branch=master)](https://travis-ci.org/paulirish/devtools-timeline-model)\n\n\n**Unsupported**. \n\nNow we recommend you use another library for parsing traces.. See https://github.com/jlfwong/speedscope/blob/main/src/import/chrome.ts and https://github.com/saucelabs/tracelib and https://github.com/GoogleChrome/lighthouse/tree/master/lighthouse-core/lib/tracehouse\n\nCheers\n\n\n---------------------\n\n\u003e Parse raw trace data into the Chrome DevTools' structured profiling data models\n\nIf you use something like [big-rig](https://github.com/googlechrome/big-rig) or [automated-chrome-profiling](https://github.com/paulirish/automated-chrome-profiling#timeline-recording) you may end up with raw trace data. It's pretty raw. This module will parse that stuff into something a bit more consumable, and should help you with higher level analysis.\n\n\n## Install\n\n```sh\n$ npm install --save devtools-timeline-model\n```\n[![NPM devtools-timeline-model package](https://img.shields.io/npm/v/devtools-timeline-model.svg)](https://npmjs.org/package/devtools-timeline-model)\n\n## Usage\n\n```js\nvar filename = 'demo/mdn-fling.json'\nvar events = require('fs').readFileSync(filename, 'utf8')\n\nvar DevtoolsTimelineModel = require('devtools-timeline-model');\n// events can be either a string of the trace data or the JSON.parse'd equivalent\nvar model = new DevtoolsTimelineModel(events)\n\n// tracing model\nmodel.tracingModel()\n// timeline model, all events\nmodel.timelineModel()\n// interaction model, incl scroll, click, animations\nmodel.interactionModel()\n// frame model, incl frame durations\nmodel.frameModel()\n// filmstrip model, incl screenshots\nmodel.filmStripModel()\n\n// topdown tree\nmodel.topDown()\n// bottom up tree\nmodel.bottomUp()\n// bottom up tree, grouped by URL\nmodel.bottomUpGroupBy('URL') // accepts: None Category Subdomain Domain URL EventName\n\n// see example.js for API examples.\n```\n\n![image](https://cloud.githubusercontent.com/assets/39191/13832447/7b4dffde-eb99-11e5-8f7e-f1afcf999fd6.png)\n\nThese objects are huge. You'll want to explore them in a UI like [devtool](https://github.com/Jam3/devtool).\n![image](https://cloud.githubusercontent.com/assets/39191/13832411/390270ec-eb99-11e5-8dc9-c647c1b62c9d.png)\n\n\n## Dev\n\n```sh\nnpm i\nbrew install entr\ngls index.js lib/*.js | entr node example.js\n```\n\n## Sandboxing WebInspector for Node\n\nRequiring the DevTools frontend looks rather straightforward at first. (`global.WebInspector = {}`, then start `require()`ing the files, in dependency order). However, there are two problems that crop up:\n\n1. The frontend requires ~five globals and they currently must be added to the global context to work. \n2. `utilities.js` adds a number of methods to native object prototypes, such as Array, Object, and typed arrays.\n\n`devtools-timeline-model` addresses that by sandboxing the WebInspector into it's own context. Here's how it works:\n\n##### index.js\n```js\n// First, sandboxed contexts don't have any globals from node, so we whitelist a few we'll provide for it.\nvar glob = { require: require, global: global, console: console, process, process, __dirname: __dirname }\n// We read in our script to run, and create a vm.Script object \nvar script  = new vm.Script(fs.readFileSync(__dirname + \"/lib/timeline-model.js\", 'utf8'))\n// We create a new V8 context with our globals\nvar ctx = vm.createContext(glob)\n// We evaluate the `vm.Script` in the new context\nvar output = script.runInContext(ctx)\n```\n##### (sandboxed) timeline-model.js\n```js\n// establish our sandboxed globals\nthis.window = this.self = this.global = this\n\n// We locally eval, as the node module scope isn't appropriate for the browser-centric DevTools frontend\nfunction requireval(path){\n  var filesrc = fs.readFileSync(__dirname + '/node_modules/' + path, 'utf8');\n  eval(filesrc + '\\n\\n//# sourceURL=' + path);\n}\n\n// polyfills, then the real chrome devtools frontend\nrequireval('../lib/api-stubs.js')\nrequireval('chrome-devtools-frontend/front_end/common/Object.js')\nrequireval('chrome-devtools-frontend/front_end/common/SegmentedRange.js')\nrequireval('chrome-devtools-frontend/front_end/platform/utilities.js')\nrequireval('chrome-devtools-frontend/front_end/sdk/Target.js')\n// ...\n```\n##### index.js\n```\n// After that's all done, we pull the local `instance` variable out, to use as our proxy object\nthis.sandbox = ctx.instance;\n```\n\nDebugging is harder, as most tools aren't used to this setup. While `devtool` doesn't work well, you can have it run `lib/devtools-timeline-model.js` directly, which is fairly succesful. The classic `node-inspector` does work pretty well with the sandboxed script, though the workflow is a little worse than `devtool`'s. \n\n\n\n## License\n\nApache © [Paul Irish](https://github.com/paulirish/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulirish%2Fdevtools-timeline-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulirish%2Fdevtools-timeline-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulirish%2Fdevtools-timeline-model/lists"}