Chrome truncates error messages and adds “” in [removed]

前端 未结 2 2169
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 12:43

We use window.onerror to catch unhandled exceptions (to log them for the dev team, and display a friendly user alert). Recently we noticed that in Google Chrome, the error messa

2条回答
  •  面向向阳花
    2021-02-05 13:10

    I found a solution that works well.

    Chrome implements the new HTML standard, in which 2 new parameters have been added to the onerror handler, namely: the colNumber, and the error object (including stack trace).

    See:

    • https://mikewest.org/2013/08/debugging-runtime-errors-with-window-onerror
    • HTML Living Standard

    The full error message can be accessed through error.message as per my code sample below. This is a duplicate of the 1st parameter message, it seems like Chrome has decided to truncate message. Not sure why they had to break something that was working... :-(

    IE and FireFox (as of my current versions: 11.0.9600 & 26.0) are not yet implementing the new 5-parameter standard, so the code makes allowance for that.

    Hope this helps someone!

    Code sample to return full error message:

    
    
        
    
    
        

    Hello World



提交回复
热议问题