Skip to content

fix: console logging for component instance proxies #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions src/output/srcdoc.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,18 @@
['clear', 'log', 'info', 'dir', 'warn', 'error', 'table'].forEach((level) => {
const original = console[level];
console[level] = (...args) => {
const msg = String(args[0])
if (
msg.includes('You are running a development build of Vue') ||
msg.includes('You are running the esm-bundler build of Vue')
) {
return
const msg = args[0]
if (typeof msg === 'string') {
if (
msg.includes('You are running a development build of Vue') ||
msg.includes('You are running the esm-bundler build of Vue')
) {
return
}
}

original(...args);

const stringifiedArgs = stringify(args);
if (
previous.level === level &&
Expand All @@ -151,13 +156,9 @@
try {
parent.postMessage({ action: 'console', level, args }, '*');
} catch (err) {
parent.postMessage({ action: 'console', level, args: args.map(a => {
return a instanceof Error ? a.message : String(a)
}) }, '*');
parent.postMessage({ action: 'console', level, args: args.map(toString) }, '*');
}
}

original(...args);
}
});

Expand Down Expand Up @@ -239,9 +240,26 @@
original_trace(...args);
};

function toString(value) {
if (value instanceof Error) {
return value.message;
}
for (const fn of [String, v => Object.prototype.toString.call(v), v => typeof v]) {
try {
return fn(value);
} catch (err) {}
}
}

function isComponentProxy(value) {
return value && typeof value === 'object' && value.__v_skip === true && typeof value.$nextTick === 'function' && value.$ && value._;
}

function stringify(args) {
try {
return JSON.stringify(args);
return JSON.stringify(args, (key, value) => {
return isComponentProxy(value) ? '{component proxy}' : value;
});
} catch (error) {
return null;
}
Expand Down