|
| 1 | +--- |
| 2 | +title: browserDebugInfoInTerminal |
| 3 | +description: Forward browser console logs and errors to your terminal during development. |
| 4 | +version: experimental |
| 5 | +--- |
| 6 | + |
| 7 | +The `experimental.browserDebugInfoInTerminal` option forwards console output and runtime errors originating in the browser to the dev server terminal. |
| 8 | + |
| 9 | +This option is disabled by default. When enabled it only works in development mode. |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +Enable forwarding: |
| 14 | + |
| 15 | +```ts filename="next.config.ts" switcher |
| 16 | +import type { NextConfig } from 'next' |
| 17 | + |
| 18 | +const nextConfig: NextConfig = { |
| 19 | + experimental: { |
| 20 | + browserDebugInfoInTerminal: true, |
| 21 | + }, |
| 22 | +} |
| 23 | + |
| 24 | +export default nextConfig |
| 25 | +``` |
| 26 | + |
| 27 | +```js filename="next.config.js" switcher |
| 28 | +/** @type {import('next').NextConfig} */ |
| 29 | +const nextConfig = { |
| 30 | + experimental: { |
| 31 | + browserDebugInfoInTerminal: true, |
| 32 | + }, |
| 33 | +} |
| 34 | + |
| 35 | +module.exports = nextConfig |
| 36 | +``` |
| 37 | + |
| 38 | +### Serialization limits |
| 39 | + |
| 40 | +Deeply nested objects/arrays are truncated using **sensible defaults**. You can tweak these limits: |
| 41 | + |
| 42 | +- **depthLimit**: (optional) Limit stringification depth for nested objects/arrays. Default: 5 |
| 43 | +- **edgeLimit**: (optional) Max number of properties or elements to include per object or array. Default: 100 |
| 44 | + |
| 45 | +```ts filename="next.config.ts" switcher |
| 46 | +import type { NextConfig } from 'next' |
| 47 | + |
| 48 | +const nextConfig: NextConfig = { |
| 49 | + experimental: { |
| 50 | + browserDebugInfoInTerminal: { |
| 51 | + depthLimit: 5, |
| 52 | + edgeLimit: 100, |
| 53 | + }, |
| 54 | + }, |
| 55 | +} |
| 56 | + |
| 57 | +export default nextConfig |
| 58 | +``` |
| 59 | + |
| 60 | +```js filename="next.config.js" switcher |
| 61 | +/** @type {import('next').NextConfig} */ |
| 62 | +const nextConfig = { |
| 63 | + experimental: { |
| 64 | + browserDebugInfoInTerminal: { |
| 65 | + depthLimit: 5, |
| 66 | + edgeLimit: 100, |
| 67 | + }, |
| 68 | + }, |
| 69 | +} |
| 70 | + |
| 71 | +module.exports = nextConfig |
| 72 | +``` |
| 73 | + |
| 74 | +### Source location |
| 75 | + |
| 76 | +Source locations are included by default when this feature is enabled. |
| 77 | + |
| 78 | +```tsx filename="app/page.tsx" highlight={8} |
| 79 | +'use client' |
| 80 | + |
| 81 | +export default function Home() { |
| 82 | + return ( |
| 83 | + <button |
| 84 | + type="button" |
| 85 | + onClick={() => { |
| 86 | + console.log('Hello World') |
| 87 | + }} |
| 88 | + > |
| 89 | + Click me |
| 90 | + </button> |
| 91 | + ) |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +Clicking the button prints this message to the terminal. |
| 96 | + |
| 97 | +```bash filename="Terminal" |
| 98 | +[browser] Hello World (app/page.tsx:8:17) |
| 99 | +``` |
| 100 | + |
| 101 | +To suppress them, set `showSourceLocation: false`. |
| 102 | + |
| 103 | +- **showSourceLocation**: Include source location info when available. |
| 104 | + |
| 105 | +```ts filename="next.config.ts" switcher |
| 106 | +import type { NextConfig } from 'next' |
| 107 | + |
| 108 | +const nextConfig: NextConfig = { |
| 109 | + experimental: { |
| 110 | + browserDebugInfoInTerminal: { |
| 111 | + showSourceLocation: false, |
| 112 | + }, |
| 113 | + }, |
| 114 | +} |
| 115 | + |
| 116 | +export default nextConfig |
| 117 | +``` |
| 118 | + |
| 119 | +```js filename="next.config.js" switcher |
| 120 | +/** @type {import('next').NextConfig} */ |
| 121 | +const nextConfig = { |
| 122 | + experimental: { |
| 123 | + browserDebugInfoInTerminal: { |
| 124 | + showSourceLocation: false, |
| 125 | + }, |
| 126 | + }, |
| 127 | +} |
| 128 | + |
| 129 | +module.exports = nextConfig |
| 130 | +``` |
| 131 | + |
| 132 | +| Version | Changes | |
| 133 | +| --------- | ---------------------------------------------------- | |
| 134 | +| `v15.4.0` | experimental `browserDebugInfoInTerminal` introduced | |
0 commit comments