Skip to content

Commit 5143045

Browse files
authored
Add information about Chrome DevTools extensibility API (#41372)
* Add information about Chrome DevTools extensibility API * Review feedback * More detail
1 parent 55ace19 commit 5143045

File tree

6 files changed

+204
-9
lines changed

6 files changed

+204
-9
lines changed

files/en-us/web/api/console/timestamp_static/index.md

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,94 @@ The **`console.timeStamp()`** static method adds a single marker to the browser'
1414

1515
You can optionally supply an argument to label the timestamp, and this label will then be shown alongside the marker.
1616

17+
Some browsers have further extended this `console.timeStamp()` method to allow additional, optional parameters to be provided as part of its extensibility API that surfaces these in performances traces. See the [Chrome's extensibility API documentation](https://developer.chrome.com/docs/devtools/performance/extension#inject_your_data_with_consoletimestamp) for more information.
18+
1719
## Syntax
1820

1921
```js-nolint
20-
console.timeStamp(label)
22+
console.timeStamp(label);
23+
console.timeStamp(label, start, end, trackName, trackGroup, color, data);
2124
```
2225

2326
### Parameters
2427

28+
- `color` {{Optional_Inline}} {{Experimental_Inline}}
29+
- : A string for the display colour of the entry. Must be one of `"primary"`, `"primary-light"`, `"primary-dark"`, `"secondary"`, `"secondary-light"`, `"secondary-dark"`, `"tertiary"`, `"tertiary-light"`, `"tertiary-dark"`, `"error"`.
30+
31+
- `data` {{Optional_Inline}} {{Experimental_Inline}}
32+
- : An object with additional data to display. URLs may automatically be turned into links by some browsers.
33+
34+
- `end` {{Optional_Inline}} {{Experimental_Inline}}
35+
- : A string referencing a previously defined `timeStamp` label or a timestamp ({{domxref("DOMHighResTimeStamp")}}) to be used as the end time.
36+
2537
- `label` {{Optional_Inline}}
2638
- : Label for the timestamp.
2739

40+
- `start` {{Optional_Inline}} {{Experimental_Inline}}
41+
- : A string referencing a previously defined `timeStamp` label or a timestamp ({{domxref("DOMHighResTimeStamp")}}) to be used as the start time.
42+
43+
- `trackName` {{Optional_Inline}} {{Experimental_Inline}}
44+
- : The name of the custom track used to display the timestamp data
45+
46+
- `trackGroup` {{Optional_Inline}} {{Experimental_Inline}}
47+
- : The group of the custom track used to display the timestamp data
48+
2849
### Return value
2950

3051
None ({{jsxref("undefined")}}).
3152

53+
## Examples
54+
55+
### Basic usage
56+
57+
```js
58+
console.timeStamp("marker 1");
59+
```
60+
61+
### Using the Extensibility API to provide richer details for display
62+
63+
```js
64+
// 1. Create a duration event with rich data
65+
const start = performance.now() - 150;
66+
const end = performance.now() - 20;
67+
68+
const durationData = {
69+
processingTime: `${end - start}ms`,
70+
info: "Check this URL: https://example.com for more.",
71+
metrics: {
72+
items: 5,
73+
isCached: true,
74+
},
75+
};
76+
77+
console.timeStamp(
78+
"My Timed Task", // label
79+
start, // startTime
80+
end, // endTime
81+
"Tasks", // trackName
82+
"My Extension", // trackGroup
83+
"tertiary", // color
84+
durationData, // data (object)
85+
);
86+
87+
// 2. Create an instant event with a deep link for a DevTools extension
88+
const linkData = {
89+
url: "ext://resource/123",
90+
description: "View Resource 123",
91+
otherDetail: "This data also appears in the JSON viewer",
92+
};
93+
94+
console.timeStamp(
95+
"Event with Link", // label
96+
performance.now(), // startTime (instant)
97+
undefined, // endTime (instant)
98+
"Tasks", // trackName
99+
"My Extension", // trackGroup
100+
"primary-light", // color
101+
linkData, // data (object)
102+
);
103+
```
104+
32105
## Browser compatibility
33106

34107
{{Compat}}
@@ -41,3 +114,4 @@ None ({{jsxref("undefined")}}).
41114
- {{domxref("performance/mark", "performance.mark()")}}
42115
- {{domxref("performance/measure", "performance.measure()")}}
43116
- [Adding markers with the console API](https://web.archive.org/web/20211207010020/https://firefox-source-docs.mozilla.org/devtools-user/performance/waterfall/index.html#adding-markers-with-the-console-api)
117+
- [Chrome DevTools extensibility API](https://developer.chrome.com/docs/devtools/performance/extension#inject_your_data_with_consoletimestamp)

files/en-us/web/api/performance/mark/index.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,22 @@ mark(name, markOptions)
2121

2222
- `name`
2323
- : A string representing the name of the mark. Must not be the same name as one of the properties of the deprecated {{domxref("PerformanceTiming")}} interface.
24+
2425
- `markOptions` {{optional_inline}}
2526
- : An object for specifying a timestamp and additional metadata for the mark.
2627
- `detail` {{optional_inline}}
2728
- : Arbitrary metadata to include in the mark. Defaults to `null`. Must be [structured-cloneable](/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
29+
- `devtools` {{optional_inline}} {{experimental_inline}}
30+
- : Some browsers have use a structured `devtools` object within the `detail` object as part of an Extensibility API that surfaces these in custom tracks in performance traces. See the [Chrome's Extensibility API documentation](https://developer.chrome.com/docs/devtools/performance/extension#inject_your_data_with_the_user_timings_api) for more information.
31+
- `dataType` {{experimental_inline}}
32+
- : A string which must be set to `marker`. Identifies as a marker.
33+
- `color` {{optional_inline}} {{experimental_inline}}
34+
- : Defaults to `"primary"`. Must be one of `"primary"`, `"primary-light"`, `"primary-dark"`, `"secondary"`, `"secondary-light"`, `"secondary-dark"`, `"tertiary"`, `"tertiary-light"`, `"tertiary-dark"`, `"error"`.
35+
- `properties` {{optional_inline}} {{experimental_inline}}
36+
- : Array of key-value pairs. Values can be any JSON-compatible type.
37+
- `tooltipText` {{optional_inline}} {{experimental_inline}}
38+
- : Short description for tooltip.
39+
2840
- `startTime` {{optional_inline}}
2941
- : {{domxref("DOMHighResTimeStamp")}} to use as the mark time. Defaults to {{domxref("performance.now()")}}.
3042

@@ -80,6 +92,27 @@ performance.mark("login-button-pressed", {
8092
});
8193
```
8294

95+
### DevTools Extensibility API
96+
97+
For browsers that support the [Extensibility API](https://developer.chrome.com/docs/devtools/performance/extension) you can use the `detail` parameter to provide more details in a `devtools` object that will be used to display this in performance profiles:
98+
99+
```js
100+
// Marker indicating when the processed image was uploaded
101+
performance.mark("Image Upload", {
102+
detail: {
103+
devtools: {
104+
dataType: "marker",
105+
color: "secondary",
106+
properties: [
107+
["Image Size", "2.5MB"],
108+
["Upload Destination", "Cloud Storage"],
109+
],
110+
tooltipText: "Processed image uploaded",
111+
},
112+
},
113+
});
114+
```
115+
83116
### Reserved names
84117

85118
Note in order to maintain backwards compatibility, names that are part of the deprecated {{domxref("PerformanceTiming")}} interface can't be used. The following example throws:

files/en-us/web/api/performance/measure/index.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,37 @@ To only provide an `endMark`, you need to provide an empty `measureOptions` obje
3939
- : An object that may contain measure options.
4040
- `detail` {{optional_inline}}
4141
- : Arbitrary metadata to be included in the measure. Defaults to `null`. Must be [structured-cloneable](/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm).
42+
- `devtools`
43+
- : Some browsers have use a structured `devtools` object within the `detail` object as part of an Extensibility API that surfaces these in custom tracks in performance traces. See the [Chrome's Extensibility API documentation](https://developer.chrome.com/docs/devtools/performance/extension#inject_your_data_with_the_user_timings_api) for more information.
44+
- `dataType` {{experimental_inline}}
45+
- : String with a value of `track-entry` (for defining a new track) or `marker` (for defining an entry in a track).
46+
- `color` {{optional_inline}} {{experimental_inline}}
47+
- : Defaults to `"primary"`. Must be one of `"primary"`, `"primary-light"`, `"primary-dark"`, `"secondary"`, `"secondary-light"`, `"secondary-dark"`, `"tertiary"`, `"tertiary-light"`, `"tertiary-dark"`, `"error"`.
48+
- `track` {{optional_inline}} {{experimental_inline}}
49+
- : String of the name of the custom track (required for `track-entry`)
50+
- `trackGroup` {{optional_inline}} {{experimental_inline}}
51+
- : String of the name of the grouping withing a custom track (required for `track-entry`)
52+
- `properties` {{optional_inline}} {{experimental_inline}}
53+
- : Array of key-value pairs. Values can be any JSON-compatible type.
54+
- `tooltipText` {{optional_inline}} {{experimental_inline}}
55+
- : Short description for tooltip.
56+
4257
- `start` {{optional_inline}}
4358
- : Timestamp ({{domxref("DOMHighResTimeStamp")}}) to be used as the start time, or string that names a {{domxref("PerformanceMark")}} to use for the start time.
4459

4560
If this is a string naming a {{domxref("PerformanceMark")}}, then it is defined in the same way as `startMark`.
4661

4762
- `duration` {{optional_inline}}
4863
- : Duration (in milliseconds) between the start and end mark times. If omitted, this defaults to {{domxref("performance.now()")}}; the time that has elapsed since the context was created. If provided, you must also specify either `start` or `end` but not both.
64+
4965
- `end` {{optional_inline}}
5066
- : Timestamp ({{domxref("DOMHighResTimeStamp")}}) to be used as the end time, or string that names a {{domxref("PerformanceMark")}} to use for the end time.
5167

5268
If this is a string naming a {{domxref("PerformanceMark")}}, then it is defined in the same way as `endMark`.
5369

5470
- `startMark` {{optional_inline}}
5571
- : A string naming a {{domxref("PerformanceMark")}} in the performance timeline. The {{domxref("PerformanceEntry.startTime")}} property of this mark will be used for calculating the measure.
72+
5673
- `endMark` {{optional_inline}}
5774
- : A string naming a {{domxref("PerformanceMark")}} in the performance timeline. The {{domxref("PerformanceEntry.startTime")}} property of this mark will be used for calculating the measure.
5875
If you want to pass this argument, you must also pass either `startMark` or an empty `measureOptions` object.
@@ -140,6 +157,44 @@ performance.measure("login-click", {
140157
});
141158
```
142159

160+
### DevTools Extensibility API
161+
162+
For browsers that support the [Extensibility API](https://developer.chrome.com/docs/devtools/performance/extension) you can use the `detail` parameter to provide more details in a `devtools` object that will be used to display this in performance profiles:
163+
164+
```js
165+
const imageProcessingTimeStart = performance.now();
166+
167+
// ... later in your code
168+
169+
performance.measure("Image Processing Complete", {
170+
start: imageProcessingTimeStart,
171+
end: performance.now(),
172+
detail: {
173+
// This data appears in the "Summary"
174+
extraInfo: {
175+
imageId: "xyz-123",
176+
source: "cache",
177+
checkUrl: "https://example.com/check/xyz-123",
178+
},
179+
// The devtools object controls the track visualization
180+
devtools: {
181+
dataType: "track-entry",
182+
track: "Image Processing Tasks",
183+
trackGroup: "My Tracks",
184+
color: "tertiary-dark",
185+
properties: [
186+
["Filter Type", "Gaussian Blur"],
187+
// Values can be objects, arrays, or other types
188+
["Resize Dimensions", { w: 500, h: 300 }],
189+
// String values that are URLs get linkified
190+
["Image URL", "https://example.com/img.png"],
191+
],
192+
tooltipText: "Image processed successfully",
193+
},
194+
},
195+
});
196+
```
197+
143198
## Specifications
144199

145200
{{Specifications}}

files/en-us/web/api/performancemark/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Entries of this type are typically created by calling {{domxref("Performance.mar
2020

2121
## Instance properties
2222

23+
- {{domxref("PerformanceMark.detail")}}
24+
- : Contains arbitrary metadata about the measure.
25+
2326
This interface extends the following {{domxref("PerformanceEntry")}} properties by qualifying/constraining the properties as follows:
2427

2528
- {{domxref("PerformanceEntry.entryType")}} {{ReadOnlyInline}}
@@ -31,11 +34,6 @@ This interface extends the following {{domxref("PerformanceEntry")}} properties
3134
- {{domxref("PerformanceEntry.duration")}} {{ReadOnlyInline}}
3235
- : Returns `0`. (A mark has no _duration_.)
3336

34-
This interface also supports the following properties:
35-
36-
- {{domxref("PerformanceMark.detail")}} {{ReadOnlyInline}}
37-
- : Returns arbitrary metadata that has been included in the mark upon construction.
38-
3937
## Instance methods
4038

4139
This interface has no methods.
@@ -44,6 +42,8 @@ This interface has no methods.
4442

4543
See the example in [Using the User Timing API](/en-US/docs/Web/API/Performance_API/User_timing).
4644

45+
Chrome DevTools uses `performance.mark()` and in particular a structured `detail` property as part of its extensibility API that surfaces these in custom tracks in performance traces. See the example in [Performance: mark() method](/en-US/docs/Web/API/Performance/mark) page and the [Chrome's extensibility API documentation](https://developer.chrome.com/docs/devtools/performance/extension#inject_your_data_with_the_user_timings_api) for more information and examples.
46+
4747
## Specifications
4848

4949
{{Specifications}}

files/en-us/web/api/performancemark/performancemark/index.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ new PerformanceMark(name, markOptions)
2727
- : An object for specifying a timestamp and additional metadata for the mark.
2828
- `detail` {{optional_inline}}
2929
- : Arbitrary metadata to include in the mark. Defaults to `null`.
30+
- `devtools` {{optional_inline}} {{experimental_inline}}
31+
- : Some browsers have use a structured `devtools` object within the `detail` object as part of an Extensibility API that surfaces these in custom tracks in performance traces. See the [Chrome's Extensibility API documentation](https://developer.chrome.com/docs/devtools/performance/extension#inject_your_data_with_the_user_timings_api) for more information.
32+
- `dataType` {{experimental_inline}}
33+
- : A string which must be set to `marker`. Identifies as a marker.
34+
- `color` {{optional_inline}} {{experimental_inline}}
35+
- : Defaults to `"primary"`. Must be one of `"primary"`, `"primary-light"`, `"primary-dark"`, `"secondary"`, `"secondary-light"`, `"secondary-dark"`, `"tertiary"`, `"tertiary-light"`, `"tertiary-dark"`, `"error"`.
36+
- `properties` {{optional_inline}} {{experimental_inline}}
37+
- : Array of key-value pairs. Values can be any JSON-compatible type.
38+
- `tooltipText` {{optional_inline}} {{experimental_inline}}
39+
- : Short description for tooltip.
3040
- `startTime` {{optional_inline}}
3141
- : {{domxref("DOMHighResTimeStamp")}} to use as the mark time. Defaults to {{domxref("performance.now()")}}.
3242

@@ -41,6 +51,8 @@ A {{domxref("PerformanceMark")}} object.
4151

4252
## Examples
4353

54+
### Creating named markers
55+
4456
The following example shows how {{domxref("PerformanceMark")}} entries are constructed and then aren't part of the browser's performance timeline.
4557

4658
```js
@@ -53,6 +65,27 @@ console.log(allEntries.length);
5365
// 0
5466
```
5567

68+
### DevTools Extensibility API
69+
70+
For browsers that support the [Extensibility API](https://developer.chrome.com/docs/devtools/performance/extension) you can use the `detail` parameter to provide more details in a `devtools` object that will be used to display this in performance profiles:
71+
72+
```js
73+
// Marker indicating when the processed image was uploaded
74+
performance.mark("Image Upload", {
75+
detail: {
76+
devtools: {
77+
dataType: "marker",
78+
color: "secondary",
79+
properties: [
80+
["Image Size", "2.5MB"],
81+
["Upload Destination", "Cloud Storage"],
82+
],
83+
tooltipText: "Processed image uploaded",
84+
},
85+
},
86+
});
87+
```
88+
5689
## Specifications
5790

5891
{{Specifications}}

files/en-us/web/api/performancemeasure/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ browser-compat: api.PerformanceMeasure
1313

1414
## Instance properties
1515

16-
This interface defines:
17-
1816
- {{domxref("PerformanceMeasure.detail")}}
1917
- : Contains arbitrary metadata about the measure.
2018

21-
In addition, it extends the following {{domxref("PerformanceEntry")}} properties by qualifying/constraining the properties as follows:
19+
This interface extends the following {{domxref("PerformanceEntry")}} properties by qualifying/constraining the properties as follows:
2220

2321
- {{domxref("PerformanceEntry.entryType")}}
2422
- : Returns `"measure"`.
@@ -37,6 +35,8 @@ This interface has no methods.
3735

3836
See the example in [Using the User Timing API](/en-US/docs/Web/API/Performance_API/User_timing).
3937

38+
Chrome DevTools uses `performance.measure()` and in particular a structured `detail` property as part of its extensibility API that surfaces these in custom tracks in performance traces. See the example in [Performance: measure() method](/en-US/docs/Web/API/Performance/measure) page and the [Chrome's extensibility API documentation](https://developer.chrome.com/docs/devtools/performance/extension#inject_your_data_with_the_user_timings_api) for more information and examples.
39+
4040
## Specifications
4141

4242
{{Specifications}}

0 commit comments

Comments
 (0)