Internet Explorer: “console is not defined” Error

前端 未结 9 1620
天涯浪人
天涯浪人 2020-12-05 18:33

I was using console.log() in some JavaScript I wrote and an error of: console is not defined was thrown in Internet Explorer (worked fine in other

9条回答
  •  甜味超标
    2020-12-05 19:03

    Some browsers do not have console enabled when the dev-tools is closed. Also, one would encounter this issue with WebViews or iFrames where console is disabled.

    The error in these cases is - Uncaught ReferenceError: console is not defined

    Inspired by many answers on here, I developed a library for this usecase: https://github.com/sunnykgupta/jsLogger

    Features:

    1. It safely overrides the console.log.
    2. Takes care if the console is not available (oh yes, you need to factor that too.)
    3. Stores all logs (even if they are suppressed) for later retrieval.
    4. Handles major console functions like log, warn, error, info.

提交回复
热议问题