|
153 | 153 | ) |
154 | 154 | } |
155 | 155 | }) |
156 | | - ;['clear', 'log', 'info', 'dir', 'warn', 'error', 'table'].forEach( |
157 | | - (level) => { |
158 | | - const original = console[level] |
159 | | - console[level] = (...args) => { |
160 | | - const msg = args[0] |
161 | | - if (typeof msg === 'string') { |
162 | | - if ( |
163 | | - msg.includes('You are running a development build of Vue') || |
164 | | - msg.includes('You are running the esm-bundler build of Vue') |
165 | | - ) { |
166 | | - return |
167 | | - } |
| 156 | + const errorColorStr = 'color: #fb2c36' |
| 157 | + const errorMsg = 'please open the devtool to see correctly this log' |
| 158 | + ;[ |
| 159 | + 'clear', |
| 160 | + 'log', |
| 161 | + 'info', |
| 162 | + 'dir', |
| 163 | + 'warn', |
| 164 | + 'error', |
| 165 | + 'table', |
| 166 | + 'debug', |
| 167 | + 'time', |
| 168 | + 'timeLog', |
| 169 | + 'timeEnd', |
| 170 | + 'assert', |
| 171 | + 'count', |
| 172 | + 'countReset', |
| 173 | + ].forEach((level) => { |
| 174 | + const original = console[level] |
| 175 | + console[level] = async (...args) => { |
| 176 | + const msg = args[0] |
| 177 | + if (typeof msg === 'string') { |
| 178 | + if ( |
| 179 | + msg.includes('You are running a development build of Vue') || |
| 180 | + msg.includes('You are running the esm-bundler build of Vue') |
| 181 | + ) { |
| 182 | + return |
168 | 183 | } |
169 | | - original(...args) |
170 | | - |
171 | | - const postMessage = () => |
172 | | - parent.postMessage({ action: 'console', level, args }, '*') |
173 | | - |
174 | | - try { |
175 | | - postMessage() |
176 | | - } catch { |
| 184 | + } |
| 185 | + original(...args) |
| 186 | + const postMessage = () => |
| 187 | + parent.postMessage({ action: 'console', level, args }, '*') |
| 188 | + try { |
| 189 | + postMessage() |
| 190 | + } catch { |
| 191 | + args = args.map(toString) |
| 192 | + if (!args?.[0]?.startsWith('[Vue warn]')) |
177 | 193 | args = [ |
178 | | - '%c Cannot clone the message, please open the devtool to see corretly this log. Supported types are listed here: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#javascript_types', |
179 | | - 'color: #fb2c36', |
| 194 | + `[vue-repl]: %c Cannot clone the message, ${errorMsg}. Supported types are listed here: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm#javascript_types`, |
| 195 | + errorColorStr, |
180 | 196 | ] |
181 | | - postMessage() |
182 | | - } |
| 197 | + postMessage() |
183 | 198 | } |
184 | | - }, |
185 | | - ) |
| 199 | + } |
| 200 | + }) |
186 | 201 | ;[ |
187 | 202 | { method: 'group', action: 'console_group' }, |
188 | 203 | { method: 'groupEnd', action: 'console_group_end' }, |
|
195 | 210 | original(label) |
196 | 211 | } |
197 | 212 | }) |
198 | | - |
199 | | - const timers = new Map() |
200 | | - const original_time = console.time |
201 | | - const original_timelog = console.timeLog |
202 | | - const original_timeend = console.timeEnd |
203 | | - |
204 | | - console.time = (label = 'default') => { |
205 | | - original_time(label) |
206 | | - timers.set(label, performance.now()) |
207 | | - } |
208 | | - console.timeLog = (label = 'default') => { |
209 | | - original_timelog(label) |
210 | | - const now = performance.now() |
211 | | - if (timers.has(label)) { |
212 | | - parent.postMessage( |
213 | | - { |
214 | | - action: 'console', |
215 | | - level: 'log', |
216 | | - args: [`${label}: ${now - timers.get(label)}ms`], |
217 | | - }, |
218 | | - '*', |
219 | | - ) |
220 | | - } else { |
221 | | - parent.postMessage( |
222 | | - { |
223 | | - action: 'console', |
224 | | - level: 'warn', |
225 | | - args: [`Timer '${label}' does not exist`], |
226 | | - }, |
227 | | - '*', |
228 | | - ) |
229 | | - } |
230 | | - } |
231 | | - console.timeEnd = (label = 'default') => { |
232 | | - original_timeend(label) |
233 | | - const now = performance.now() |
234 | | - if (timers.has(label)) { |
235 | | - parent.postMessage( |
236 | | - { |
237 | | - action: 'console', |
238 | | - level: 'log', |
239 | | - args: [`${label}: ${now - timers.get(label)}ms`], |
240 | | - }, |
241 | | - '*', |
242 | | - ) |
243 | | - } else { |
244 | | - parent.postMessage( |
245 | | - { |
246 | | - action: 'console', |
247 | | - level: 'warn', |
248 | | - args: [`Timer '${label}' does not exist`], |
249 | | - }, |
250 | | - '*', |
251 | | - ) |
| 213 | + ;['profile', 'profileEnd', 'trace', 'dirXml'].forEach((level) => { |
| 214 | + const original = console[level] |
| 215 | + console[level] = () => { |
| 216 | + original() |
| 217 | + const args = [ |
| 218 | + `[vue-repl]: %c Cannot handle "${level}" log, ${errorMsg}.`, |
| 219 | + errorColorStr, |
| 220 | + ] |
| 221 | + parent.postMessage({ action: 'console', level: 'log', args }, '*') |
252 | 222 | } |
253 | | - timers.delete(label) |
254 | | - } |
255 | | - |
256 | | - const original_assert = console.assert |
257 | | - console.assert = (condition, ...args) => { |
258 | | - if (condition) { |
259 | | - const stack = new Error().stack |
260 | | - parent.postMessage( |
261 | | - { action: 'console', level: 'assert', args, stack }, |
262 | | - '*', |
263 | | - ) |
264 | | - } |
265 | | - original_assert(condition, ...args) |
266 | | - } |
267 | | - |
268 | | - const counter = new Map() |
269 | | - const original_count = console.count |
270 | | - const original_countreset = console.countReset |
271 | | - |
272 | | - console.count = (label = 'default') => { |
273 | | - counter.set(label, (counter.get(label) || 0) + 1) |
274 | | - parent.postMessage( |
275 | | - { |
276 | | - action: 'console', |
277 | | - level: 'log', |
278 | | - args: [`${label}: ${counter.get(label)}`], |
279 | | - }, |
280 | | - '*', |
281 | | - ) |
282 | | - original_count(label) |
283 | | - } |
284 | | - |
285 | | - console.countReset = (label = 'default') => { |
286 | | - if (counter.has(label)) { |
287 | | - counter.set(label, 0) |
288 | | - } else { |
289 | | - parent.postMessage( |
290 | | - { |
291 | | - action: 'console', |
292 | | - level: 'warn', |
293 | | - args: [`Count for '${label}' does not exist`], |
294 | | - }, |
295 | | - '*', |
296 | | - ) |
297 | | - } |
298 | | - original_countreset(label) |
299 | | - } |
300 | | - |
301 | | - const original_trace = console.trace |
302 | | - |
303 | | - console.trace = (...args) => { |
304 | | - const stack = new Error().stack |
305 | | - parent.postMessage( |
306 | | - { action: 'console', level: 'trace', args, stack }, |
307 | | - '*', |
308 | | - ) |
309 | | - original_trace(...args) |
310 | | - } |
| 223 | + }) |
311 | 224 |
|
312 | 225 | function toString(value) { |
313 | 226 | if (value instanceof Error) { |
|
0 commit comments