Suppress the error messages generated from the package

533 Views Asked by At

I am using a Go function which roughly works as follows:

  • It traverses the given URL and searches for a string
  • For traversing the websites I have used Chrome DevTools package.

My problem is while it's doing the traversal, it logs some error messages like

ERROR: encountered exception 'Uncaught' (287:57) etc.

I have to suppress this error printing in the console. I have checked chrome-dp issues and I think it's a known issue, Reference: https://github.com/chromedp/chromedp/issues/374#issuecomment-498015901

How can I avoid this printing directly into the console?

2

There are 2 best solutions below

0
Volker On

How can I avoid this printing directly into the console ?

You cannot from Go code. You can filter the output and remove these after wards. e.g. with grep.

0
chmike On

Inside the Go program, you can redirect stdout and stderr. All you need is redirect them, and filter the data. You probably only need to filter stderr if the errors are output through stderr.

You can test if the errors are output on stderr by using redirections in the shell.