Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document PerformanceMark constructor #21821

Merged
merged 2 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions files/en-us/web/api/performance/mark/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,23 @@ mark(name, markOptions)
### Parameters

- `name`

- : A string representing the name of the mark. If the
`name` given to this method already exists in the
{{domxref("PerformanceTiming")}} interface, {{jsxref("SyntaxError")}} is
thrown.

- : A string representing the name of the mark.
- `markOptions` {{optional_inline}}

- : An object for specifying a timestamp and additional metadata for the mark.

- `detail`
- : Arbitrary metadata to include in the mark.
- `startTime`
- : {{domxref("DOMHighResTimeStamp")}} to use as the mark time.
- `detail` {{optional_inline}}
- : Arbitrary metadata to include in the mark. Defaults to `null`.
- `startTime` {{optional_inline}}
- : {{domxref("DOMHighResTimeStamp")}} to use as the mark time. Defaults to {{domxref("performance.now()")}}.

### Return value

The {{domxref("PerformanceMark")}} entry that was created.

### Exceptions

- {{jsxref("SyntaxError")}}: Thrown if the `name` given to this method already exists in the {{domxref("PerformanceTiming")}} interface.
- {{jsxref("TypeError")}}: Thrown if `startTime` is negative.

## Examples

The following example shows how to use `mark()` to create and retrieve
Expand Down
9 changes: 8 additions & 1 deletion files/en-us/web/api/performancemark/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ browser-compat: api.PerformanceMark

{{APIRef("User Timing API")}}

**`PerformanceMark`** is an _abstract_ interface for {{domxref("PerformanceEntry")}} objects with an {{domxref("PerformanceEntry.entryType","entryType")}} of "`mark`". Entries of this type are created by calling {{domxref("Performance.mark","performance.mark()")}} to add a _named_ {{domxref("DOMHighResTimeStamp")}} (the _mark_) to the browser's _performance timeline_.
**`PerformanceMark`** is an interface for {{domxref("PerformanceEntry")}} objects with an {{domxref("PerformanceEntry.entryType","entryType")}} of "`mark`".

Entries of this type are typically created by calling {{domxref("Performance.mark","performance.mark()")}} to add a _named_ {{domxref("DOMHighResTimeStamp")}} (the _mark_) to the browser's performance timeline. To create a performance mark that isn't added to the browser's performance timeline, use the constructor.

{{InheritanceDiagram}}

{{AvailableInWorkers}}

## Constructor

- {{domxref("PerformanceMark.PerformanceMark", "PerformanceMark()")}}
- : Creates a new `PerformanceMark` object that isn't added to the browser's performance timeline.

## Instance properties

This interface has no properties but it extends the following {{domxref("PerformanceEntry")}} properties by qualifying/constraining the properties as follows:
Expand Down
70 changes: 70 additions & 0 deletions files/en-us/web/api/performancemark/performancemark/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
title: PerformanceMark()
slug: Web/API/PerformanceMark/PerformanceMark
page-type: web-api-constructor
tags:
- API
- Constructor
- Reference
- Web Performance
browser-compat: api.PerformanceMark.PerformanceMark
---

{{APIRef("User Timing API")}}

The **`PerformanceMark()`** constructor creates a {{domxref("DOMHighResTimeStamp","timestamp")}} with the given name.

Unlike {{domxref("Performance.mark","performance.mark()")}}, performance marks created by the constructor aren't added to the browser's performance timeline. This means that calls to the {{domxref("Performance")}} interface's `getEntries*()` methods ({{domxref("Performance.getEntries","getEntries()")}}, {{domxref("Performance.getEntriesByName","getEntriesByName()")}} or {{domxref("Performance.getEntriesByType","getEntriesByType()")}}) won't show entries for these marks.

## Syntax

```js-nolint
new PerformanceMark(name)
new PerformanceMark(name, markOptions)
```

### Parameters

- `name`
- : A string representing the name of the mark.
- `markOptions` {{optional_inline}}
- : An object for specifying a timestamp and additional metadata for the mark.
- `detail` {{optional_inline}}
- : Arbitrary metadata to include in the mark. Defaults to `null`.
- `startTime` {{optional_inline}}
- : {{domxref("DOMHighResTimeStamp")}} to use as the mark time. Defaults to {{domxref("performance.now()")}}.

### Return value

A {{domxref("PerformanceMark")}} object.

### Exceptions

- {{jsxref("SyntaxError")}}: Thrown if the `name` given to this method already exists in the {{domxref("PerformanceTiming")}} interface.
- {{jsxref("TypeError")}}: Thrown if `startTime` is negative.

## Examples

The following example shows how {{domxref("PerformanceMark")}} entries are constructed and then aren't part of the browser's performance timeline.

```js
new PerformanceMark("squirrel");
new PerformanceMark("monkey");
new PerformanceMark("dog");

const allEntries = performance.getEntriesByType("mark");
console.log(allEntries.length);
// 0
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("Performance.mark","performance.mark()")}}