@@ -14,19 +14,36 @@ const isValidURL = (url: string): boolean => {
1414 return false ;
1515 }
1616} ;
17+ const getContent = ( entry : chrome . devtools . network . Request ) : Promise < string > => {
18+ return new Promise ( ( resolve ) => {
19+ entry . getContent ( ( content ) => {
20+ resolve ( content || '' ) ;
21+ } ) ;
22+ } ) ;
23+ } ;
24+ const isValidJSONString = ( content : string ) : boolean => {
25+ try {
26+ JSON . parse ( content ) ;
27+ return true ;
28+ } catch ( e ) {
29+ return false ;
30+ }
31+ } ;
32+
1733const validStatuses = new Set ( [ "GET" , "POST" , "PUT" , "DELETE" , "PATCH" ] ) ;
1834const validResourceTypes = new Set ( [ "xhr" , "fetch" ] ) ;
1935const isValidStatus = ( status : string ) => validStatuses . has ( status ) ;
20- export const isValidRequest = (
36+ export const isValidRequest = async (
2137 harRequest : chrome . devtools . network . Request
22- ) : boolean => {
38+ ) : Promise < boolean > => {
2339 const isNotAJAXRequest =
2440 ! ! harRequest . _resourceType &&
2541 ! validResourceTypes . has ( harRequest . _resourceType ) ;
2642 if ( isNotAJAXRequest ) return false ;
2743 const didNotReachServer = ! harRequest . serverIPAddress ;
2844 if ( didNotReachServer ) return false ;
29- const isNotJSON = harRequest . response . content . mimeType !== "application/json" ;
45+ const content = await getContent ( harRequest ) ;
46+ const isNotJSON = harRequest . response . content . mimeType !== "application/json" && ! isValidJSONString ( content ) ;
3047 if ( isNotJSON ) return false ;
3148 const isNotValidStatus = ! isValidStatus ( harRequest . request . method ) ;
3249 if ( isNotValidStatus ) return false ;
0 commit comments