UNPKG

playwright-fluent

Version:
40 lines (39 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.recordPageErrors = void 0; const os_1 = require("os"); async function recordPageErrors(page, callback) { if (!page) { throw new Error(`Cannot record page errors because no browser has been launched`); } page.on('pageerror', (err) => { callback(err); }); page.on('console', async (msg) => { try { if (msg.type() === 'error') { const location = msg.location(); const text = msg .text() .replace(/JSHandle@object/g, '') .trim(); const args = msg.args(); const stackTrace = []; stackTrace.push(`at '${location.url}'`); stackTrace.push(`line: ${location.lineNumber}`); for (let index = 1; index < args.length; index++) { const arg = args[index]; const argValue = JSON.stringify(await arg.jsonValue(), null, 2); stackTrace.push(argValue); } const err = new Error(text); err.stack = stackTrace.join(os_1.EOL); callback(err); } } catch (error) { callback(error); } }); } exports.recordPageErrors = recordPageErrors;