Skip to content

[Improvement] Disable console output improvement #691

@da411d

Description

@da411d

Today disableConsoleOutput looks like this:

const func = function () {};
const that = GLOBAL;
if (!that.console) {
  that.console = (function (func){
    const c = {};
    
    c.log = func;
    c.warn = func;
    c.debug = func;
    c.info = func;
    c.error = func;
    c.exception = func;
    c.table = func;
    c.trace = func;
    
    return c;
  })(func);
} else {
  that.console.log = func;
  that.console.warn = func;
  that.console.debug = func;
  that.console.info = func;
  that.console.error = func;
  that.console.exception = func;
  that.console.table = func;
  that.console.trace = func;
}

Yes, it just works, but if we type console.log in console, we see empty function:
image

My improvement idea is to override toString method to make it look more realistic:
image
For this you need add just 3 lines of code to current template:

var toString = () => "function () { [native code] }";
toString.toString = toString;
func.toString = toString;

Now it looks more realistic, but still not perfect. We can bind original toStinrg method to new empty function:
image

Now console.log looks like native function.

const cons = window.console;
for(let key in cons){
  const originalFunction = cons[key];
  if(typeof originalFunction !== "function") continue;
  const func = function () {};
  func.toString = originalFunction.toString.bind(originalFunction);
  cons[key] = func;
};

I'm not sure this improvement matters, or just "works - don't touch"

UPD: seems it don't work for firefox, just Chromium, but Chromium is used by more users

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions