Open History to see the last commit
1---
2id: devtools
3title: Devtools
4---
5β
6> For Chrome, Firefox, and Edge users: Third-party browser extensions are available for debugging TanStack Query directly in browser DevTools. These provide the same functionality as the framework-specific devtools packages:
7>
8> - <img alt="Chrome logo" src="https://www.google.com/chrome/static/images/chrome-logo.svg" width="16" height="16" class="inline mr-1 not-prose" /> [Devtools for Chrome](https://chromewebstore.google.com/detail/tanstack-query-devtools/annajfchloimdhceglpgglpeepfghfai)
9> - <img alt="Firefox logo" src="https://upload.wikimedia.org/wikipedia/commons/a/a0/Firefox_logo%2C_2019.svg" width="16" height="16" class="inline mr-1 not-prose" /> [Devtools for Firefox](https://addons.mozilla.org/en-US/firefox/addon/tanstack-query-devtools/)
10> - <img alt="Edge logo" src="https://upload.wikimedia.org/wikipedia/commons/9/98/Microsoft_Edge_logo_%282019%29.svg" width="16" height="16" class="inline mr-1 not-prose" /> [Devtools for Edge](https://microsoftedge.microsoft.com/addons/detail/tanstack-query-devtools/edmdpkgkacmjopodhfolmphdenmddobj)
11β
12## Enable devtools
13β
14Add the devtools package (in addition to `@tanstack/angular-query-experimental`):
15β
16```bash
17npm install @tanstack/angular-query-devtools
18```
19β
20The devtools help you debug and inspect your queries and mutations. You can enable the devtools by adding `withDevtools` to `provideTanStackQuery`.
21β
22By default, Angular Query Devtools only load in development.
23β
24```ts
25import {
26 QueryClient,
27 provideTanStackQuery,
28} from '@tanstack/angular-query-experimental'
29β
30import { withDevtools } from '@tanstack/angular-query-devtools'
31β
32export const appConfig: ApplicationConfig = {
33 providers: [...provideTanStackQuery(new QueryClient(), withDevtools())],
34}
35```
36β
37## Devtools in production
38β
39If you need the real implementation in production, import from the `production` entrypoint.
40β
41```ts
42import { withDevtools } from '@tanstack/angular-query-devtools/production'
43```
44β
45To control when devtools are loaded, use the `loadDevtools` option.
46β
47When omitted or set to `'auto'`, devtools only load in development mode.
48β
49```ts
50import { withDevtools } from '@tanstack/angular-query-devtools'
51β
52providers: [...provideTanStackQuery(new QueryClient(), withDevtools())]
53β
54// which is equivalent to
55providers: [
56 provideTanStackQuery(
57 new QueryClient(),
58 withDevtools(() => ({ loadDevtools: 'auto' })),
59 ),
60]
61```
62β
63When setting the option to true, the devtools will be loaded in both development and production mode.
64β
65This is useful if you want to load devtools based on [Angular environment configurations](https://angular.dev/tools/cli/environments). E.g. you could set this to true when the application is running on your production build staging environment.
66β
67```ts
68import { environment } from './environments/environment'
69// Make sure to use the production sub-path to load devtools in production builds
70import { withDevtools } from '@tanstack/angular-query-devtools/production'
71β
72providers: [
73 provideTanStackQuery(
74 new QueryClient(),
75 withDevtools(() => ({ loadDevtools: environment.loadDevtools })),
76 ),
77]
78```
79β
80When setting the option to false, the devtools will not be loaded.
81β
82```ts
83providers: [
84 provideTanStackQuery(
85 new QueryClient(),
86 withDevtools(() => ({ loadDevtools: false })),
87 ),
88]
89```
90β
91## Derive options through reactivity
92β
93Options can be returned from a callback so they can react to signals. For example, a signal derived from a keyboard shortcut can enable devtools on demand:
94β
95```ts
96import { Injectable, isDevMode } from '@angular/core'
97import { fromEvent, map, scan } from 'rxjs'
98import { toSignal } from '@angular/core/rxjs-interop'
99β
100@Injectable({ providedIn: 'root' })
101export class DevtoolsOptionsManager {
102 loadDevtools = toSignal(
103 fromEvent<KeyboardEvent>(document, 'keydown').pipe(
104 map(
105 (event): boolean =>
106 event.metaKey && event.ctrlKey && event.shiftKey && event.key === 'D',
107 ),
108 scan((acc, curr) => acc || curr, isDevMode()),
109 ),
110 {
111 initialValue: isDevMode(),
112 },
113 )
114}
115```
116β
117To use an injectable such as a service in the callback, pass it through `deps`:
118β
119```ts
120// ...
121// π Note we import from the production sub-path to enable devtools lazy loading in production builds
122import { withDevtools } from '@tanstack/angular-query-devtools/production'
123β
124export const appConfig: ApplicationConfig = {
125 providers: [
126 provideHttpClient(),
127 provideTanStackQuery(
128 new QueryClient(),
129 withDevtools(
130 (devToolsOptionsManager: DevtoolsOptionsManager) => ({
131 loadDevtools: devToolsOptionsManager.loadDevtools(),
132 }),
133 {
134 deps: [DevtoolsOptionsManager],
135 },
136 ),
137 ),
138 ],
139}
140```
141β
142### Options returned from the callback
143β
144Of these options `loadDevtools`, `client`, `position`, `errorTypes`, `buttonPosition`, and `initialIsOpen` support reactivity through signals.
145β
146- `loadDevtools?: 'auto' | boolean`
147 - Omit or `'auto'`: load devtools only in development mode.
148 - Use this to control whether devtools load when using the `/production` import.
149- `initialIsOpen?: Boolean`
150 - Set this to `true` if you want the tools to default to being open
151- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
152 - Defaults to `bottom-right`
153 - The position of the TanStack logo to open and close the devtools panel
154 - If `relative`, the button is placed in the location that you render the devtools.
155- `position?: "top" | "bottom" | "left" | "right"`
156 - Defaults to `bottom`
157 - The position of the Angular Query devtools panel
158- `client?: QueryClient`,
159 - Use this to use a custom QueryClient. Otherwise, the QueryClient provided through `provideTanStackQuery` will be injected.
160- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
161 - Use this to predefine some errors that can be triggered on your queries. Initializer will be called (with the specific query) when that error is toggled on from the UI. It must return an Error.
162- `styleNonce?: string`
163 - Use this to pass a nonce to the style tag that is added to the document head. This is useful if you are using a Content Security Policy (CSP) nonce to allow inline styles.
164- `shadowDOMTarget?: ShadowRoot`
165 - Default behavior will apply the devtool's styles to the head tag within the DOM.
166 - Use this to pass a shadow DOM target to the devtools so that the styles will be applied within the shadow DOM instead of within the head tag in the light DOM.
167- `hideDisabledQueries?: boolean`
168 - Set this to true to hide disabled queries from the devtools panel.