The mark()
method creates a timestamp
in the browser's performance entry buffer with the given name.
The application defined timestamp can be retrieved by one of the Performance
interface's getEntries*()
methods (getEntries()
, getEntriesByName()
or getEntriesByType()
).
The mark()'s
stores its data internally as PerformanceEntry
.
Note: This feature is available in Web Workers.
Syntax
performance.mark(name);
Arguments
- name
- A
DOMString
representing the name of the mark. If thename
given to this method already exists in thePerformanceTiming
interface,SyntaxError
is thrown.
Return value
- void
Example
The following example shows how to use mark()
to create and retrieve PerformanceMark
entries.
// Create a bunch of marks. performance.mark("squirrel"); performance.mark("squirrel"); performance.mark("monkey"); performance.mark("monkey"); performance.mark("dog"); performance.mark("dog"); // Get all of the PerformanceMark entries. const allEntries = performance.getEntriesByType("mark"); console.log(allEntries.length); // 6 // Get all of the "monkey" PerformanceMark entries. const monkeyEntries = performance.getEntriesByName("monkey"); console.log(monkeyEntries.length); // 2 // Clear out all of the marks. performance.clearMarks();
Specifications
Specification | Status | Comment |
---|---|---|
User Timing Level 2 The definition of 'mark()' in that specification. |
Working Draft | Clarifies mark() processing model. |
User Timing The definition of 'mark()' in that specification. |
Recommendation | Basic definition. |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
mark | Chrome
Full support
28
| Edge Full support 12 | Firefox Full support 41 | IE Full support 10 | Opera Full support 33 | Safari Full support 11 | WebView Android Full support Yes | Chrome Android
Full support
28
| Firefox Android Full support 42 | Opera Android Full support 33 | Safari iOS Full support 11 | Samsung Internet Android Full support 1.5 |
Legend
- Full support
- Full support
- Requires a vendor prefix or different name for use.
- Requires a vendor prefix or different name for use.