How to take all consoles.logs, errors, and alerts from the console to cleinte (devtools)

Asked

Viewed 22 times

0

I have a next.JS application and I need it to be well indexed. I’m making some changes and improvements following Lighthouse. However a mistake of "good practices" appeared that I always had doubts.

How to get everything you have on the console for the customer? How to make all errors, alerts, consoles logs etc no longer appear to the client in case he of F12.

I believe it is possible, because big sites like facebook have nothing on the console, and we know that hardly a site will not have consoles, errors and alerts, especially with the size and complexity of facebook. Google sites even have nothing.

inserir a descrição da imagem aqui

1 answer

0

Opa, there are libs that can help you with this, but you can also create a console wrapper to help you, the idea is to check the environment that is running and run or not console.log.

A small example.

const log = { info: (msg) => { if(ENV==="PROD") return; console.log(msg)  } }

Here the ENV variable is an environment variable that informs the environment in which it is being executed (production, development, Stage, local), in case of production nothing is executed.

[Obs] Check what can be impacted by not running the console.log.

Utilizing:

log.info("Executando operação XYZ");

I hope I’ve helped.

  • Very interesting friend, I will try to do this way. Which libs do that ? Do you know any?.

  • And this wrapper would be where? Would it be just a component created to stay around the entire site? or would it be put on the site public by JS script

Browser other questions tagged

You are not signed in. Login or sign up in order to post.