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β
14The devtools help you debug and inspect your queries and mutations. You can enable the devtools by adding `withDevtools` to `provideTanStackQuery`.
15β
16By default, the devtools are enabled when Angular [`isDevMode`](https://angular.dev/api/core/isDevMode) returns true. So you don't need to worry about excluding them during a production build. The core tools are lazily loaded and excluded from bundled code. In most cases, all you'll need to do is add `withDevtools()` to `provideTanStackQuery` without any additional configuration.
17β
18```ts
19import {
20 QueryClient,
21 provideTanStackQuery,
22 withDevtools,
23} from '@tanstack/angular-query-experimental'
24β
25export const appConfig: ApplicationConfig = {
26 providers: [provideTanStackQuery(new QueryClient(), withDevtools())],
27}
28```
29β
30## Configuring if devtools are loaded
31β
32If you need more control over when devtools are loaded, you can use the `loadDevtools` option. This is particularly useful if you want to load devtools based on environment configurations. For instance, you might have a test environment running in production mode but still require devtools to be available.
33β
34When not setting the option or setting it to 'auto', the devtools will be loaded when Angular is in development mode.
35β
36```ts
37provideTanStackQuery(new QueryClient(), withDevtools())
38β
39// which is equivalent to
40provideTanStackQuery(
41 new QueryClient(),
42 withDevtools(() => ({ loadDevtools: 'auto' })),
43)
44```
45β
46When setting the option to true, the devtools will be loaded in both development and production mode.
47β
48```ts
49provideTanStackQuery(
50 new QueryClient(),
51 withDevtools(() => ({ loadDevtools: true })),
52)
53```
54β
55When setting the option to false, the devtools will not be loaded.
56β
57```ts
58provideTanStackQuery(
59 new QueryClient(),
60 withDevtools(() => ({ loadDevtools: false })),
61)
62```
63β
64The `withDevtools` options are returned from a callback function to support reactivity through signals. In the following example
65a signal is created from a RxJS observable that listens for a keyboard shortcut. When the event is triggered, the devtools are lazily loaded.
66Using this technique allows you to support on-demand loading of the devtools even in production mode, without including the full tools in the bundled code.
67β
68```ts
69@Injectable({ providedIn: 'root' })
70class DevtoolsOptionsManager {
71 loadDevtools = toSignal(
72 fromEvent<KeyboardEvent>(document, 'keydown').pipe(
73 map(
74 (event): boolean =>
75 event.metaKey && event.ctrlKey && event.shiftKey && event.key === 'D',
76 ),
77 scan((acc, curr) => acc || curr, false),
78 ),
79 {
80 initialValue: false,
81 },
82 )
83}
84β
85export const appConfig: ApplicationConfig = {
86 providers: [
87 provideHttpClient(),
88 provideTanStackQuery(
89 new QueryClient(),
90 withDevtools(() => ({
91 initialIsOpen: true,
92 loadDevtools: inject(DevtoolsOptionsManager).loadDevtools(),
93 })),
94 ),
95 ],
96}
97```
98β
99### Options
100β
101Of these options `client`, `position`, `errorTypes`, `buttonPosition`, and `initialIsOpen` support reactivity through signals.
102β
103- `loadDevtools?: 'auto' | boolean`
104 - Defaults to `auto`: lazily loads devtools when in development mode. Skips loading in production mode.
105 - Use this to control if the devtools are loaded.
106- `initialIsOpen?: Boolean`
107 - Set this to `true` if you want the tools to default to being open
108- `buttonPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | "relative"`
109 - Defaults to `bottom-right`
110 - The position of the TanStack logo to open and close the devtools panel
111 - If `relative`, the button is placed in the location that you render the devtools.
112- `position?: "top" | "bottom" | "left" | "right"`
113 - Defaults to `bottom`
114 - The position of the Angular Query devtools panel
115- `client?: QueryClient`,
116 - Use this to use a custom QueryClient. Otherwise, the QueryClient provided through `provideTanStackQuery` will be injected.
117- `errorTypes?: { name: string; initializer: (query: Query) => TError}[]`
118 - 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.
119- `styleNonce?: string`
120 - 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.
121- `shadowDOMTarget?: ShadowRoot`
122 - Default behavior will apply the devtool's styles to the head tag within the DOM.
123 - 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.