@@ -174,43 +174,37 @@ export const init = (sdk: FrontendSDK) => {
174174 // Helper function to extract request IDs from BaseContext (replay and http-history pages)
175175 const getRequestIdsFromBaseContext = ( ) : string [ ] => {
176176 try {
177- let requestId : string | undefined ;
177+ // Simple approach: find any element with data-request-id attribute
178+ const element = document . querySelector ( "[data-request-id]" ) ;
178179
179- switch ( location . hash ) {
180- case "#/http-history" : {
181- console . log ( "Getting request from http-history HTML" ) ;
182-
183- // there's always a request selected in http history
184- requestId = document
185- . querySelector ( ".c-response[data-request-id]" )
186- ?. getAttribute ( "data-request-id" ) as string ;
187-
188- break ;
189- }
190- case "#/replay" : {
191- console . log ( "Getting request from replay HTML" ) ;
192-
193- const div : Element | null = document . querySelector (
194- ".c-response[data-request-id]"
195- ) ;
196- if ( ! div ) {
197- throw new Error ( "Request must be sent first" ) ;
198- }
199-
200- requestId = div . getAttribute ( "data-request-id" ) as string ;
201- break ;
202- }
203- default :
204- throw new Error ( "Can't find request" ) ;
180+ if ( ! element ) {
181+ throw new Error ( "No element with data-request-id found in current page" ) ;
205182 }
206183
207- if ( requestId ) {
208- return [ requestId ] ;
209- } else {
210- throw new Error ( "No request ID found in current page" ) ;
184+ const requestId = element . getAttribute ( "data-request-id" ) ;
185+
186+ if ( ! requestId ) {
187+ throw new Error ( "Element found but data-request-id attribute is empty" ) ;
188+
211189 }
190+
191+ console . log ( `Found request ID: ${ requestId } ` ) ;
192+ console . log ( `Element details:` , {
193+ tag : element . tagName ,
194+ classes : element . className ,
195+ id : element . id ,
196+ } ) ;
197+
198+ // If requestId starts with "v", show toast to user to send request first
199+ if ( requestId !== undefined && requestId . charAt ( 0 ) === "v" ) {
200+ sdk . window . showToast ( "Please send the request first before using this feature." , { variant : "warning" } ) ;
201+ return [ ] ;
202+ }
203+
204+ return [ requestId ] ;
212205 } catch ( error ) {
213206 const errorMessage = error instanceof Error ? error . message : String ( error ) ;
207+ sdk . window . showToast ( errorMessage , { variant : "error" } ) ;
214208 throw new Error ( `No request found in current page: ${ errorMessage } ` ) ;
215209 }
216210 } ;
0 commit comments