Skip to content

Commit bb0e143

Browse files
fix: console logging for component instance proxies (#62)
1 parent eb41c3a commit bb0e143

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

src/output/srcdoc.html

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,18 @@
138138
['clear', 'log', 'info', 'dir', 'warn', 'error', 'table'].forEach((level) => {
139139
const original = console[level];
140140
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+
}
147149
}
150+
151+
original(...args);
152+
148153
const stringifiedArgs = stringify(args);
149154
if (
150155
previous.level === level &&
@@ -158,13 +163,9 @@
158163
try {
159164
parent.postMessage({ action: 'console', level, args }, '*');
160165
} 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) }, '*');
164167
}
165168
}
166-
167-
original(...args);
168169
}
169170
});
170171

@@ -246,9 +247,26 @@
246247
original_trace(...args);
247248
};
248249

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+
249265
function stringify(args) {
250266
try {
251-
return JSON.stringify(args);
267+
return JSON.stringify(args, (key, value) => {
268+
return isComponentProxy(value) ? '{component proxy}' : value;
269+
});
252270
} catch (error) {
253271
return null;
254272
}

0 commit comments

Comments
 (0)