0

Wondering if chrome console.log allows you to go back and rewrite existing console.log output, like you can do in Node.js. I know you can do colors in the chrome console, but not sure about editing existing text. Would like to try adding a progress bar such as:

enter image description here

I'm getting this:

enter image description here

msanford
  • 10,127
  • 8
  • 56
  • 83
Lance Pollard
  • 66,757
  • 77
  • 237
  • 416
  • Once output is evaluated and written to the console, you can't change it. However, you [can style it with CSS](https://stackoverflow.com/questions/7505623/colors-in-javascript-console) (which you might be able to hack to allow that behaviour). – msanford Jan 09 '18 at 14:56
  • FYI, latest version of Chrome (as mine Version 71.0.3578.98) support ansi color in console natively, so you won't get ansi escape code but the colored text. – alphakevin Dec 29 '18 at 04:42
  • Since Chrome 69, basic ansi escape codes are supported. – Richie Bendall Nov 24 '20 at 07:24

1 Answers1

1

Try calling console.clear (chrome, MDN) in a loop. This works as long as you have ‘preserve log’ turned off. It flickers a bit for me in Chrome’s console, but such is life (it's actually great in Firefox).

delay=t=>new Promise(resolve=>setTimeout(resolve,t));

// the stack snippets console emulator doesn't seem
// to work if the very first call is clear.
console.log();

(async()=>{
  for(i=0;i<25;i++){
    console.clear();
    console.log('*'.repeat(i));
    await delay(100);
  }
})()
Josh Lee
  • 149,877
  • 34
  • 253
  • 263