|
138 | 138 | ['clear', 'log', 'info', 'dir', 'warn', 'error', 'table'].forEach((level) => { |
139 | 139 | const original = console[level]; |
140 | 140 | console[level] = (...args) => { |
141 | | - const msg = String(args[0]) |
142 | | - if ( |
143 | | - msg.includes('You are running a development build of Vue') || |
144 | | - msg.includes('You are running the esm-bundler build of Vue') |
145 | | - ) { |
146 | | - return |
| 141 | + const msg = args[0] |
| 142 | + if (typeof msg === 'string') { |
| 143 | + if ( |
| 144 | + msg.includes('You are running a development build of Vue') || |
| 145 | + msg.includes('You are running the esm-bundler build of Vue') |
| 146 | + ) { |
| 147 | + return |
| 148 | + } |
147 | 149 | } |
| 150 | + |
| 151 | + original(...args); |
| 152 | + |
148 | 153 | const stringifiedArgs = stringify(args); |
149 | 154 | if ( |
150 | 155 | previous.level === level && |
|
158 | 163 | try { |
159 | 164 | parent.postMessage({ action: 'console', level, args }, '*'); |
160 | 165 | } catch (err) { |
161 | | - parent.postMessage({ action: 'console', level, args: args.map(a => { |
162 | | - return a instanceof Error ? a.message : String(a) |
163 | | - }) }, '*'); |
| 166 | + parent.postMessage({ action: 'console', level, args: args.map(toString) }, '*'); |
164 | 167 | } |
165 | 168 | } |
166 | | - |
167 | | - original(...args); |
168 | 169 | } |
169 | 170 | }); |
170 | 171 |
|
|
246 | 247 | original_trace(...args); |
247 | 248 | }; |
248 | 249 |
|
| 250 | + function toString(value) { |
| 251 | + if (value instanceof Error) { |
| 252 | + return value.message; |
| 253 | + } |
| 254 | + for (const fn of [String, v => Object.prototype.toString.call(v), v => typeof v]) { |
| 255 | + try { |
| 256 | + return fn(value); |
| 257 | + } catch (err) {} |
| 258 | + } |
| 259 | + } |
| 260 | + |
| 261 | + function isComponentProxy(value) { |
| 262 | + return value && typeof value === 'object' && value.__v_skip === true && typeof value.$nextTick === 'function' && value.$ && value._; |
| 263 | + } |
| 264 | + |
249 | 265 | function stringify(args) { |
250 | 266 | try { |
251 | | - return JSON.stringify(args); |
| 267 | + return JSON.stringify(args, (key, value) => { |
| 268 | + return isComponentProxy(value) ? '{component proxy}' : value; |
| 269 | + }); |
252 | 270 | } catch (error) { |
253 | 271 | return null; |
254 | 272 | } |
|
0 commit comments