(page)
| 115 | } |
| 116 | |
| 117 | async function registerConsoleMessage(page) { |
| 118 | page.on("console", (msg) => { |
| 119 | if (consoleLogsTool) { |
| 120 | const type = msg.type(); |
| 121 | const text = msg.text(); |
| 122 | |
| 123 | // "Unhandled Rejection In Promise" we injected |
| 124 | if (text.startsWith("[Playwright]")) { |
| 125 | const payload = text.replace("[Playwright]", ""); |
| 126 | if (consoleLogsTool) { |
| 127 | consoleLogsTool.registerConsoleMessage("exception", payload); |
| 128 | } |
| 129 | } else { |
| 130 | if (consoleLogsTool) { |
| 131 | consoleLogsTool.registerConsoleMessage(type, text); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | }); |
| 136 | |
| 137 | // Uncaught exception |
| 138 | page.on("pageerror", (error) => { |
| 139 | if (consoleLogsTool) { |
| 140 | const message = error.message; |
| 141 | const stack = error.stack || ""; |
| 142 | consoleLogsTool.registerConsoleMessage("exception", `${message}\n${stack}`); |
| 143 | } |
| 144 | }); |
| 145 | |
| 146 | // Unhandled rejection in promise |
| 147 | await page.addInitScript(() => { |
| 148 | window.addEventListener("unhandledrejection", (event) => { |
| 149 | const reason = event.reason; |
| 150 | const message = typeof reason === "object" && reason !== null |
| 151 | ? reason.message || JSON.stringify(reason) |
| 152 | : String(reason); |
| 153 | |
| 154 | const stack = reason?.stack || ""; |
| 155 | // Use console.error get "Unhandled Rejection In Promise" |
| 156 | console.error(`[Playwright][Unhandled Rejection In Promise] ${message}\n${stack}`); |
| 157 | }); |
| 158 | }); |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Attempts to install browsers automatically |
no test coverage detected