* Signature designed, so it can work with window.onerror * @param {string|undefined} message * @param {string|undefined} filename * @param {string|undefined} line * @param {string|undefined} col * @param {*|undefined} error * @this {!Window|undefined}
(message, filename, line, col, error)
| 319 | * @this {!Window|undefined} |
| 320 | */ |
| 321 | function onError(message, filename, line, col, error) { |
| 322 | // Make an attempt to unhide the body but don't if the error is actually expected. |
| 323 | // eslint-disable-next-line local/no-invalid-this |
| 324 | if (this && this.document && (!error || !error.expected)) { |
| 325 | // eslint-disable-next-line local/no-invalid-this |
| 326 | makeBodyVisibleRecovery(this.document); |
| 327 | } |
| 328 | if (getMode().localDev || getMode().development || getMode().test) { |
| 329 | return; |
| 330 | } |
| 331 | let hasNonAmpJs = false; |
| 332 | try { |
| 333 | hasNonAmpJs = detectNonAmpJs(self); |
| 334 | } catch (ignore) { |
| 335 | // Ignore errors during error report generation. |
| 336 | } |
| 337 | if (hasNonAmpJs && Math.random() < NON_AMP_JS_ERROR_THRESHOLD) { |
| 338 | return; |
| 339 | } |
| 340 | const data = getErrorReportData( |
| 341 | message, |
| 342 | filename, |
| 343 | line, |
| 344 | col, |
| 345 | error, |
| 346 | hasNonAmpJs |
| 347 | ); |
| 348 | if (data) { |
| 349 | reportingBackoff(() => { |
| 350 | try { |
| 351 | return reportErrorToServerOrViewer( |
| 352 | // eslint-disable-next-line local/no-invalid-this |
| 353 | this, |
| 354 | /** @type {!JsonObject} */ |
| 355 | (data) |
| 356 | ).catch(() => { |
| 357 | // catch async errors to avoid recursive errors. |
| 358 | }); |
| 359 | } catch (e) { |
| 360 | // catch async errors to avoid recursive errors. |
| 361 | } |
| 362 | }); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Determines the error reporting endpoint which should be used. |
no test coverage detected