Information report

更新时间:
复制 MD 格式

This topic describes the JavaScript APIs of WVReporter. You can refer to this topic when you create HTML5 apps or Miniapps. You can use the JavaScript APIs of WVReporter to report page information, such as JavaScript errors, time to first byte (TTFB), and DOM loading time.

WVReporter.reportDomLoad

Reports the TTFB and DOM loading time of the current page to tag HTML5 apps or MiniApps.

In the iOS system, WindVane 8.2.0 or later automatically captures the time of the DOMContentLoaded event. WVReporter.reportDomLoad does not conflict with page tags.

Input parameters

  • [number]firstByte: the TTFB of the current page. Unit: milliseconds. TTFB can be obtained by using the Date.now() method.

  • [number]time: the DOM loading time of the current page. Unit: milliseconds. The DOM loading time can be obtained by using the Date.now() method.

Callback parameters

No callback parameters exist. If the TTFB and DOM loading time of the page was reported, the success callback is invoked. Otherwise, the failure callback is invoked.

(function () {
        var firstByteTime = Date.now();
        document.addEventListener("DOMContentLoaded", function () {
                if (window.WindVane) {
                        var params = {
                                firstByte: firstByteTime,
                                time: Date.now()
                        };
                        window.WindVane.call("WVReporter", "reportDomLoad", params);
                }
        }, false);
})();

WVReporter.reportError

Reports the JavaScript error on the current page, which is uploaded with the WindVane:JavaScriptError tag of AppMonitor.

In the iOS system, WindVane 8.2.0 or later automatically captures JavaScript errors and sets from = 'WindVane' to distinguish the WindVane:JavaScriptError tag from manually added tags.

Input parameters

  • [string]file: the JavaScript file where a JavaScript error occurred.

  • [string]url: (optional) the URL to which the JavaScript error is uploaded. By default, the URL of the current page is used.

  • [string]msg: the JavaScript error message.

  • [string]line: the line number of the line at which the error occurred in JavaScript.

  • [string]col: the column number of the column at which the error occurred in JavaScript.

  • [string]tack: the JavaScript stack in which the error occurred in JavaScript.

  • [string]from: (optional) the source of the error tag, used to recognize an error that recurs many times.

Callback parameters

No callback parameters exist. If the JavaScript error on the page was reported, the success callback is invoked. Otherwise, the failure callback is invoked.

Example

(function () {
        if (window.WindVane) {
                var oldOnError = window.onerror
                window.onerror = function (message, file, lineno, colno, error) {
                        var params = {
                                file: file,
                                msg: message
                                line: lineno,
                                col: colno,
                                stack: error ? error.stack : ''
                        };
                        window.WindVane.call("WVReporter", "reportError", params);
                        if (oldOnError) {
                                return oldOnError(message, file, lineno)
                        }
                        return false
                }
        }
})();