How to add custom Timeline layers and events
masterYou can extend the Vue Devtools Timeline by adding custom layers and events:
- Register a layer: Use
addTimelineLayerto define a new layer with a uniqueid,color, andlabel. - Send events: Use
addTimelineEventto record occurrences. Each event requires alayerIdand aneventobject containing atime(useapi.now()) anddata. - Group events: To group multiple events into a single pill-shaped rectangle in the UI, assign the same
groupIdto theeventobject of all related events. This allows the inspector to show the total duration of the group.
Early Proxy: If you need to send timeline events before the Devtools are fully connected (e.g., during early app initialization), set the enableEarlyProxy: true option in setupDevtoolsPlugin. This provides a proxy api that buffers calls until the real API is available.
// Register layer
api.addTimelineLayer({
id: 'my-layer',
color: 0xff984f,
label: 'Awesome!'
})
// Send grouped event
const groupId = 'task-1'
api.addTimelineEvent({
layerId: 'my-layer',
event: {
time: api.now(),
data: { info: 'starting' },
groupId
}
})