Error.stackTraceLimit

Non-standard: This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

Note: This feature is part of the currently non-standard V8 stack trace API. However, for compatibility reasons, it is also implemented by JavaScriptCore.

The Error.stackTraceLimit static data property indicates the maximum number of stack frames captured by the stack trace of an error. It can be set by user code to change the engine's behavior.

Generally, reading this property is not very useful, but you can set it to a new value. Setting it to a larger value can be useful for debugging, as it allows you to see more of the call stack. Setting it to a smaller value can improve performance as it reduces the amount of stack captured.

Value

An integer representing the maximum number of stack frames captured by the stack trace of an error.

Property attributes of Error.stackTraceLimit
Writableyes
Enumerableyes
Configurableyes

Description

Because stackTraceLimit is a static property of Error, you always use it as Error.stackTraceLimit, rather than as a property of an Error object you created. If you want to customize the stack trace for a single error only, you may need to set the property, create the error, and then reset the property to its original value.

Examples

Setting Error.stackTraceLimit

This code is safe to run even in environments that don't support Error.stackTraceLimit, because it doesn't read the property, only sets it, and engines that don't support it will ignore the setting.

js
Error.stackTraceLimit = 2;
const a = () => b();
const b = () => c();
const c = () => d();
const d = () => e();
const e = () => {
  throw new Error("My error");
};
try {
  a();
} catch (e) {
  console.log(e.stack);
}
// Only two frames in supporting engines; all frames in others

Specifications

No specification found

No specification data found for javascript.builtins.Error.stackTraceLimit.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
stackTraceLimit
Non-standard

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Non-standard. Check cross-browser support before using.

See also