@@ -16,7 +16,12 @@ const activeConnections = new Map<string, ConnectionInfo>();
1616// Message types
1717interface TanStackQueryMessage {
1818 type : "QEVENT" ;
19- subtype : "QUERY_CLIENT_DETECTED" | "QUERY_CLIENT_NOT_FOUND" | "QUERY_STATE_UPDATE" | "QUERY_DATA_UPDATE" | "MUTATION_DATA_UPDATE" ;
19+ subtype :
20+ | "QUERY_CLIENT_DETECTED"
21+ | "QUERY_CLIENT_NOT_FOUND"
22+ | "QUERY_STATE_UPDATE"
23+ | "QUERY_DATA_UPDATE"
24+ | "MUTATION_DATA_UPDATE" ;
2025 payload ?: unknown ;
2126}
2227
@@ -107,93 +112,100 @@ chrome.runtime.onConnect.addListener(async (port) => {
107112 // Forward messages to content script if needed
108113 const currentTabId = await getCurrentTabId ( ) ;
109114 if ( currentTabId && message . type ) {
110- chrome . tabs . sendMessage ( currentTabId , message ) . catch ( ( error : unknown ) => {
111- console . warn ( "Failed to send message to content script:" , error ) ;
112- } ) ;
115+ chrome . tabs
116+ . sendMessage ( currentTabId , message )
117+ . catch ( ( error : unknown ) => {
118+ console . warn ( "Failed to send message to content script:" , error ) ;
119+ } ) ;
113120 }
114121 } ) ;
115122 }
116123} ) ;
117124
118125// Handle messages from content scripts
119- chrome . runtime . onMessage . addListener ( ( message : TanStackQueryMessage | QueryActionResult , sender , sendResponse ) => {
120- const tabId = sender . tab ?. id ;
121- if ( ! tabId ) return ;
122-
123- if ( message . type === "QEVENT" ) {
124- switch ( message . subtype ) {
125- case "QUERY_CLIENT_DETECTED" :
126- tabsWithTanStackQuery . add ( tabId ) ;
127-
128- // Forward to DevTools panel
129- devtoolsPort ?. postMessage ( {
130- type : "QEVENT" ,
131- subtype : "QUERY_CLIENT_DETECTED" ,
132- tabId : tabId ,
133- payload : message . payload ,
134- } ) ;
135- break ;
126+ chrome . runtime . onMessage . addListener (
127+ ( message : TanStackQueryMessage | QueryActionResult , sender , sendResponse ) => {
128+ const tabId = sender . tab ?. id ;
129+ if ( ! tabId ) return ;
130+
131+ if ( message . type === "QEVENT" ) {
132+ switch ( message . subtype ) {
133+ case "QUERY_CLIENT_DETECTED" :
134+ tabsWithTanStackQuery . add ( tabId ) ;
135+
136+ // Forward to DevTools panel
137+ devtoolsPort ?. postMessage ( {
138+ type : "QEVENT" ,
139+ subtype : "QUERY_CLIENT_DETECTED" ,
140+ tabId : tabId ,
141+ payload : message . payload ,
142+ } ) ;
143+ break ;
136144
137- case "QUERY_CLIENT_NOT_FOUND" :
138- tabsWithTanStackQuery . delete ( tabId ) ;
145+ case "QUERY_CLIENT_NOT_FOUND" :
146+ tabsWithTanStackQuery . delete ( tabId ) ;
139147
140- // Forward to DevTools panel
141- devtoolsPort ?. postMessage ( {
142- type : "QEVENT" ,
143- subtype : "QUERY_CLIENT_NOT_FOUND" ,
144- tabId : tabId ,
145- payload : message . payload ,
146- } ) ;
147- break ;
148-
149- case "QUERY_STATE_UPDATE" :
150- // Forward to DevTools panel
151- devtoolsPort ?. postMessage ( {
152- type : "QEVENT" ,
153- subtype : "QUERY_STATE_UPDATE" ,
154- tabId : tabId ,
155- payload : message . payload ,
156- } ) ;
157- break ;
158-
159- case "QUERY_DATA_UPDATE" :
160- // Forward to DevTools panel
161- devtoolsPort ?. postMessage ( {
162- type : "QEVENT" ,
163- subtype : "QUERY_DATA_UPDATE" ,
164- tabId : tabId ,
165- payload : message . payload ,
166- } ) ;
167- break ;
168-
169- case "MUTATION_DATA_UPDATE" :
170- // Forward to DevTools panel
171- devtoolsPort ?. postMessage ( {
172- type : "QEVENT" ,
173- subtype : "MUTATION_DATA_UPDATE" ,
174- tabId : tabId ,
175- payload : message . payload ,
176- } ) ;
177- break ;
148+ // Forward to DevTools panel
149+ devtoolsPort ?. postMessage ( {
150+ type : "QEVENT" ,
151+ subtype : "QUERY_CLIENT_NOT_FOUND" ,
152+ tabId : tabId ,
153+ payload : message . payload ,
154+ } ) ;
155+ break ;
156+
157+ case "QUERY_STATE_UPDATE" :
158+ // Forward to DevTools panel
159+ devtoolsPort ?. postMessage ( {
160+ type : "QEVENT" ,
161+ subtype : "QUERY_STATE_UPDATE" ,
162+ tabId : tabId ,
163+ payload : message . payload ,
164+ } ) ;
165+ break ;
166+
167+ case "QUERY_DATA_UPDATE" :
168+ // Forward to DevTools panel
169+ devtoolsPort ?. postMessage ( {
170+ type : "QEVENT" ,
171+ subtype : "QUERY_DATA_UPDATE" ,
172+ tabId : tabId ,
173+ payload : message . payload ,
174+ } ) ;
175+ break ;
176+
177+ case "MUTATION_DATA_UPDATE" :
178+ // Forward to DevTools panel
179+ devtoolsPort ?. postMessage ( {
180+ type : "QEVENT" ,
181+ subtype : "MUTATION_DATA_UPDATE" ,
182+ tabId : tabId ,
183+ payload : message . payload ,
184+ } ) ;
185+ break ;
186+ }
178187 }
179- }
180188
181- // Handle query action results from content script
182- if ( message . type === "QUERY_ACTION_RESULT" ) {
183- // Forward to DevTools panel
184- devtoolsPort ?. postMessage ( {
185- ...message ,
186- tabId : tabId ,
187- } ) ;
188- }
189+ // Handle query action results from content script
190+ if ( message . type === "QUERY_ACTION_RESULT" ) {
191+ // Forward to DevTools panel
192+ devtoolsPort ?. postMessage ( {
193+ ...message ,
194+ tabId : tabId ,
195+ } ) ;
196+ }
189197
190- sendResponse ( { received : true } ) ;
191- } ) ;
198+ sendResponse ( { received : true } ) ;
199+ } ,
200+ ) ;
192201
193202// Helper function to get current active tab ID
194203async function getCurrentTabId ( ) : Promise < number | null > {
195204 try {
196- const [ tab ] = await chrome . tabs . query ( { active : true , currentWindow : true } ) ;
205+ const [ tab ] = await chrome . tabs . query ( {
206+ active : true ,
207+ currentWindow : true ,
208+ } ) ;
197209 return tab ?. id || null ;
198210 } catch ( error ) {
199211 console . warn ( "Failed to get current tab ID:" , error ) ;
0 commit comments