-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Background:
Chrome represents anonymous callbacks of methods like Array.forEach
in stacktraces in a weird way.
When presented with code like this:
function caller() {
someArray.forEach((item) => { // line x
erroringFunction(); // line y
});
}
function erroringFunction() {
throw new Error("nope"); // line z
}
caller(); // line q
instead of doing this:
erroringFunction at line z, col j in someScript.js
<anonymous> at line y, col k in someScript.js
Array.forEach at line x col m in someScript.js
caller at line x, col n in someScript.js
at line q, col p in someScript.js
it does this:
erroringFunction at line z, col j in someScript.js
at line y, col k in myscript.js
Array.forEach in <anonymous>
caller at line x, col n in someScript.js
at line q, col p in someScript.js
losing the function name on the second frame and and on the third frame, losting line and column values and using <anonymous>
as the script name.
(For the record, though Firefox and Safari each do it differently, each one does include the correct script name in the relevant frames.)
Problem:
As a result of the above, we don't have a filename to use for either sourcemapping or in-app detection. That in turn leads to incorrect situations like this, where the code both calling and called by the anonymous forEach
callback is non-in-app, but the callback itself is marked in-app :
(There may be other built-in functions taking callbacks affected by this, too, though Array.forEach
is the only one I've personally observed.)
Solution:
During processing, check the frame before the Array.forEach in <anonymous>
frame, and use its in_app
value.
Related to #51072.