这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
ReportingObserver
接口在
Reporting API
allows you to collect and access reports.
ReportingObserver()
ReportingObserver
object instance, which can be used to collect and access reports.
This interface has no properties defined on it.
ReportingObserver.disconnect()
Stops a reporting observer that had previously started observing from collecting reports.
ReportingObserver.observe()
Instructs a reporting observer to start collecting reports in its report queue.
ReportingObserver.takeRecords()
Returns the current list of reports contained in the observer's report queue, and empties the queue.
This interface has no events that fire on it.
In our deprecation_report.html example, we create a simple reporting observer to observe usage of deprecated features on our web page:
let options = {
types: ['deprecation'],
buffered: true
}
let observer = new ReportingObserver(function(reports, observer) {
reportBtn.onclick = () => displayReports(reports);
}, options);
We then tell it to start observing reports using
ReportingObserver.observe()
; this tells the observer to start collecting reports in its report queue, and runs the callback function specified inside the constructor:
observer.observe();
Later on in the example we deliberately use the deprecated version of
MediaDevices.getUserMedia()
:
if(navigator.mozGetUserMedia) {
navigator.mozGetUserMedia(
constraints,
success,
failure);
} else {
navigator.getUserMedia(
constraints,
success,
failure);
}
This causes a deprecation report to be generated; because of the event handler we set up inside the
ReportingObserver()
constructor, we can now click the button to display the report details.
注意
: If you look at the
complete source code
, you'll notice that we actually call the deprecated
getUserMedia()
method twice. After the first time we call
ReportingObserver.takeRecords()
, which returns the first generated report and empties the queue. Because of this, when the button is pressed only the second report is listed.
| 规范 | 状态 | 注释 |
|---|---|---|
|
Reporting API
The definition of 'ReportingObserver' in that specification. |
编者草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
ReportingObserver
|
Chrome 69 | Edge 79 | Firefox No | IE No | Opera 56 | Safari No | WebView Android 69 | Chrome Android 69 | Firefox Android No | Opera Android 48 | Safari iOS No | Samsung Internet Android 10.0 |
ReportingObserver()
构造函数
|
Chrome 69 | Edge 79 | Firefox No | IE No | Opera 56 | Safari No | WebView Android 69 | Chrome Android 69 | Firefox Android No | Opera Android 48 | Safari iOS No | Samsung Internet Android 10.0 |
disconnect
|
Chrome 69 | Edge 79 | Firefox No | IE No | Opera 56 | Safari No | WebView Android 69 | Chrome Android 69 | Firefox Android No | Opera Android 48 | Safari iOS No | Samsung Internet Android 10.0 |
observe
|
Chrome 69 | Edge 79 | Firefox No | IE No | Opera 56 | Safari No | WebView Android 69 | Chrome Android 69 | Firefox Android No | Opera Android 48 | Safari iOS No | Samsung Internet Android 10.0 |
takeRecords
|
Chrome 69 | Edge 79 | Firefox No | IE No | Opera 56 | Safari No | WebView Android 69 | Chrome Android 69 | Firefox Android No | Opera Android 48 | Safari iOS No | Samsung Internet Android 10.0 |
| Available in workers | Chrome 84 | Edge 84 | Firefox No | IE No | Opera 70 | Safari No | WebView Android 84 | Chrome Android 84 | Firefox Android No | Opera Android No | Safari iOS No | Samsung Internet Android No |
完整支持
不支持
实验。期望将来行为有所改变。