InterventionReportBody
注意:此功能在 Web Workers 中可用。
InterventionReportBody 介面是 Reporting API 的一部分,代表干預報告(intervention report)的正文。
當 Web 文件中的某個功能因安全、效能或使用者煩擾等原因被瀏覽器阻止使用時,會生成干預報告。例如,一個指令碼因為顯著拖慢瀏覽器速度而被停止執行,或者瀏覽器的自動播放策略阻止了在使用者未進行手勢操作的情況下播放音訊。
當被 ReportingObserver 觀察的文件中使用了已棄用的功能(例如已棄用的 API 方法)時,會生成棄用報告。除了對該 API 的支援外,接收有用的干預警告還依賴於瀏覽器供應商為相關功能新增這些警告。
建構函式
當 Report.Type 為 intervention 時,InterventionReportBody 的例項將作為 Report.body 的值返回。該介面沒有建構函式。
例項屬性
此介面還繼承了 ReportBody 的屬性。
InterventionReportBody.id實驗性 只讀-
一個表示生成報告的干預的字串。可用於對報告進行分組。
InterventionReportBody.message實驗性 只讀-
一個包含干預的可讀描述的字串,包括如何避免干預的資訊。這通常與瀏覽器在干預發生時在其開發者工具控制檯中顯示的相同訊息匹配(如果可用)。
InterventionReportBody.sourceFile實驗性 只讀-
一個字串,包含干預發生時原始碼檔案的路徑,如果已知則返回路徑,否則返回
null。 InterventionReportBody.lineNumber實驗性 只讀-
一個字串,表示干預發生時原始碼檔案的行號,如果已知則返回行號,否則返回
null。 InterventionReportBody.columnNumber實驗性 只讀-
一個字串,表示干預發生時原始碼檔案的列號,如果已知則返回列號,否則返回
null。
例項方法
此介面還繼承了 ReportBody 的方法。
InterventionReportBody.toJSON()實驗性-
一個序列化器,返回
InterventionReportBody物件的 JSON 表示形式。
示例
在此示例中,我們建立一個新的 ReportingObserver 來觀察干預報告,然後將第一個報告的每個屬性的詳細資訊列印到控制檯。
const options = {
types: ["intervention"],
buffered: true,
};
const observer = new ReportingObserver((reports, observer) => {
const firstReport = reports[0];
console.log(firstReport.type); // intervention
console.log(firstReport.body.id);
console.log(firstReport.body.message);
console.log(firstReport.body.sourceFile);
console.log(firstReport.body.lineNumber);
console.log(firstReport.body.columnNumber);
}, options);
規範
| 規範 |
|---|
| 干預報告 # 干預報告 |
瀏覽器相容性
載入中…