Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. DeprecationReportBody

DeprecationReportBody

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Note: This feature is available inWeb Workers.

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

TheDeprecationReportBody interface of theReporting API represents the body of a deprecation report.

A deprecation report is generated when a deprecated feature (for example a deprecated API method) is used on a document being observed by aReportingObserver. In addition to the support of this API, receiving useful deprecation warnings relies on browser vendors adding these warnings for deprecated features.

Constructor

An instance ofDeprecationReportBody is returned as the value ofReport.body whenReport.Type isdeprecation. The interface has no constructor.

Instance properties

This interface also inherits properties fromReportBody.

DeprecationReportBody.idExperimental

A string representing the feature or API that is deprecated, for exampleNavigatorGetUserMedia. This can be used to group reports by deprecated feature.

DeprecationReportBody.anticipatedRemovalExperimental

ADate object (rendered as a string) representing the date when the feature is expected to be removed from the current browser. If the date is not known, this property will returnnull.

DeprecationReportBody.messageExperimental

A string containing a human-readable description of the deprecation, including information such as what newer feature has superseded it, if any. This typically matches the message a browser will display in its DevTools console when a deprecated feature is used, if one is available.

DeprecationReportBody.sourceFileExperimental

A string containing the path to the source file where the deprecated feature was used, if known, ornull otherwise.

DeprecationReportBody.lineNumberExperimental

A number representing the line in the source file in which the deprecated feature was used, if known, ornull otherwise.

DeprecationReportBody.columnNumberExperimental

A number representing the column in the source file in which the deprecated feature was used, if known, ornull otherwise.

Instance methods

This interface also inherits methods fromReportBody.

DeprecationReportBody.toJSON()Experimental

Aserializer which returns a JSON representation of theInterventionReportBody object.

Examples

In ourdeprecation_report.html example, we create a simple reporting observer to observe usage of deprecated features on our web page:

js
const options = {  types: ["deprecation"],  buffered: true,};const observer = new ReportingObserver((reports, observer) => {  reportBtn.onclick = () => displayReports(reports);}, options);

We then tell it to start observing reports usingReportingObserver.observe(); this tells the observer to start collecting reports in its report queue, and runs the callback function specified inside the constructor:

js
observer.observe();

Because of the event handler we set up inside theReportingObserver() constructor, we can now click the button to display the report details.

image of a jolly bearded man with various stats displayed below it about a deprecated feature

The report details are displayed via thedisplayReports() function, which takes the observer callback'sreports parameter as its parameter:

js
function displayReports(reports) {  const outputElem = document.querySelector(".output");  const list = document.createElement("ul");  outputElem.appendChild(list);  reports.forEach((report, i) => {    const listItem = document.createElement("li");    const textNode = document.createTextNode(      `Report ${i + 1}, type: ${report.type}`,    );    listItem.appendChild(textNode);    const innerList = document.createElement("ul");    listItem.appendChild(innerList);    list.appendChild(listItem);    for (const [key, value] of Object.entries(report.body)) {      const innerListItem = document.createElement("li");      innerListItem.textContent = `${key}: ${value}`;      innerList.appendChild(innerListItem);    }  });}

Thereports parameter contains an array of all the reports in the observer's report queue. We loop over each report using a basicfor loop, then iterate over each entry of in the report's body (aDeprecationReportBody instance) using afor...in structure, displaying each key/value pair inside a list item.

Specifications

Specification
Deprecation Reporting
# deprecationreportbody

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp