@@ -14,19 +14,36 @@ const isValidURL = (url: string): boolean => {
14
14
return false ;
15
15
}
16
16
} ;
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
+
17
33
const validStatuses = new Set ( [ "GET" , "POST" , "PUT" , "DELETE" , "PATCH" ] ) ;
18
34
const validResourceTypes = new Set ( [ "xhr" , "fetch" ] ) ;
19
35
const isValidStatus = ( status : string ) => validStatuses . has ( status ) ;
20
- export const isValidRequest = (
36
+ export const isValidRequest = async (
21
37
harRequest : chrome . devtools . network . Request
22
- ) : boolean => {
38
+ ) : Promise < boolean > => {
23
39
const isNotAJAXRequest =
24
40
! ! harRequest . _resourceType &&
25
41
! validResourceTypes . has ( harRequest . _resourceType ) ;
26
42
if ( isNotAJAXRequest ) return false ;
27
43
const didNotReachServer = ! harRequest . serverIPAddress ;
28
44
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 ) ;
30
47
if ( isNotJSON ) return false ;
31
48
const isNotValidStatus = ! isValidStatus ( harRequest . request . method ) ;
32
49
if ( isNotValidStatus ) return false ;
0 commit comments