web worker console.log

前端 未结 2 838
面向向阳花
面向向阳花 2020-12-10 10:16

Is it just me, or is console.log() too much to ask for from HTML5 web workers?

I know that manipulating the DOM is blocked because it is potentially dan

2条回答
  •  一生所求
    2020-12-10 10:53

    Just wanted to post that console.log is now possible atleast within the Chrome Browser.

    I do not know which version it was added but 35.0.1916.153 m has it.

    Limitation

    There is a small limitation with it though, It can only output primitives (strings, numbers, booleans) sometimes single dimension arrays.

    And it can only take the first argument within the console log.

    Normal Console log:

    console.log("status:", _status); // status: working
    console.log({ status: _status }); // { "status": working }
    

    Worker Console log:

    console.log("status:", _status); // status:
    console.log({ status: _status }); // [object Object]
    

    You could use console.log(JSON.stringify({ status: _status })); but this would not handle circular referencing objects and will not output in a pretty/easy to read objects.

    Update: You can get pretty print with stringify by doing console.log(JSON.stringify(someObject, null, " "));.

提交回复
热议问题