This Snippet should log two warnings:
(async () => {
console.warn(new Error("blah"));
})();
console.warn(new Error("blah"));
but it actually logs one error:
Error: { "message": "Script error.", "filename": "https://stacksnippets.net/scripts/snippet-javascript-console.min.js?v=2", "lineno": 0, "colno": 0 }
In the native browser console, I see this, however:
Uncaught TypeError: e[0].indexOf is not a function warn https://stacksnippets.net/scripts/snippet-javascript-console.min.js?v=2:1 <anonymous> https://stacksnippets.net/js:16 snippet-javascript-console.min.js:1:5319 warn https://stacksnippets.net/scripts/snippet-javascript-console.min.js?v=2:1 <anonymous> https://stacksnippets.net/js:16
Uncaught (in promise) TypeError: e[0].indexOf is not a function warn https://stacksnippets.net/scripts/snippet-javascript-console.min.js?v=2:1 <anonymous> https://stacksnippets.net/js:13 <anonymous> https://stacksnippets.net/js:14 snippet-javascript-console.min.js:1:5319
The culprit seems to be (from https://stacksnippets.net/scripts/snippet-javascript-console.js line 361 and following):
console.warn = function () {
var args = arguments;
// Since we are *intentionally* running this in-browser,
// we can suppress this message as it's more annoying than helpful
if (args[0].indexOf('You are using the in-browser Babel transformer') !== -1)
return;
/* [...] */
};
This can be worked around by prepending a '%o'
argument, but the workaround doesn’t work particularly well either, as it displays the error as "{}":
console.warn('%o', new Error("blah"));
(Encountered at https://stackoverflow.com/a/79527319/3840170, in case anyone is wondering.)
-
I'd love to see some TLC for the Stack Snippets console... we've seen hints that they done some dev on snippets as a whole in the midst of the Stacks Editor work, but AFAIK the virtual console hasn't seen meaningful work make it to the public site since its release in 2016. It doesn't support ES6 types, much less anything newer (not that Error is newer!), and historically we've struggled just to keep up-to-date library support in the dropdown selectors.zcoop98– zcoop982025年04月21日 23:14:15 +00:00Commented Apr 21 at 23:14
You must log in to answer this question.
Explore related questions
See similar questions with these tags.