Select to view content in your preferred language

ArcGIS Maps SDK for Javascript 4.x - disable console error messages

1290
5
Jump to solution
08-09-2023 06:01 AM
BhavinSanghani
Frequent Contributor

How can we disable following types of error messages displayed on the browser console under Developer Tools? Is there any flag with 4.x API?

init.js:203 Uncaught (in promise) q {name: 'identity-manager:user-aborted', details: undefined, message: 'ABORTED'}

0 Kudos
2 Solutions

Accepted Solutions
AndrewMurdoch1
Frequent Contributor

Good Day

This is how I disable the console messages.  This allows you to turn off different message types, so in production you can disable all logging, which is generally a good idea.

const disableErr: boolean = false;
const disableLog: boolean = false;
const disableTime: boolean = true;

if (window && disableLog) {
  window.console.log = () => {
  };

  window.console.table = () => {
  };

  window.console.info = () => {
  };
}

if (window) {
  if (disableErr) {
    window.console.error = () => {
    };
  }

  if (disableTime) {
    window.console.time = () => {
    };

    window.console.timeLog = () => {
    };

    window.console.timeEnd = () => {
    };
  }
}

 
Cheers

View solution in original post

0 Kudos
BhavinSanghani
Frequent Contributor

Looks like Andrew has given alternative way to achieve it. Thanks @AndrewMurdoch1 and @JoelBennett ! 

However, I found esri/config has log level and that can be useful. 

View solution in original post

5 Replies
JoelBennett
MVP Regular Contributor

You can use the filtering tools in your Developer Tools console to hide any unwanted messages, as described here and here.  For example, I prefer not to be inundated with error messages about missing tiles, so I usually have the filter:

-blankTile=false -esri.views.2d.layers.TileLayerView2D

In your case, perhaps you could have:

-identity-manager:user-aborted

0 Kudos
BhavinSanghani
Frequent Contributor

Thanks for replying @JoelBennett .

I just don't want to display these console messages coming from the API to our customers as they might be least concerned with that. I know they can be helpful for debugging. But it's better if the API has some flag value or logging level to set. 

0 Kudos
AndrewMurdoch1
Frequent Contributor

Good Day

This is how I disable the console messages.  This allows you to turn off different message types, so in production you can disable all logging, which is generally a good idea.

const disableErr: boolean = false;
const disableLog: boolean = false;
const disableTime: boolean = true;

if (window && disableLog) {
  window.console.log = () => {
  };

  window.console.table = () => {
  };

  window.console.info = () => {
  };
}

if (window) {
  if (disableErr) {
    window.console.error = () => {
    };
  }

  if (disableTime) {
    window.console.time = () => {
    };

    window.console.timeLog = () => {
    };

    window.console.timeEnd = () => {
    };
  }
}

 
Cheers

0 Kudos
JoelBennett
MVP Regular Contributor

Ok, I see.  Unfortunately, the API has no such flag.  Attached is every use of "console" in the API, and you can see it is quite often used unconditionally.  Perhaps the best alternative is to override the console object's functions in a manner as mentioned by Andrew.

0 Kudos
BhavinSanghani
Frequent Contributor

Looks like Andrew has given alternative way to achieve it. Thanks @AndrewMurdoch1 and @JoelBennett ! 

However, I found esri/config has log level and that can be useful.