@@ -762,8 +762,8 @@ public function modifyResponse(Request $request, Response $response)
762
762
$ app ['log ' ]->error ('Debugbar exception: ' . $ e ->getMessage ());
763
763
}
764
764
} elseif (
765
- $ this -> isJsonRequest ( $ request ) &&
766
- $ app [ ' config ' ]-> get ( ' debugbar.capture_ajax ' , true )
765
+ $ app [ ' config ' ]-> get ( ' debugbar.capture_ajax ' , true ) &&
766
+ ( $ this -> isJsonRequest ( $ request ) || $ this -> isJsonResponse ( $ response ) )
767
767
) {
768
768
try {
769
769
if ($ this ->hasCollector ('views ' ) && $ response ->headers ->has ('X-Inertia ' )) {
@@ -790,11 +790,11 @@ public function modifyResponse(Request $request, Response $response)
790
790
}
791
791
} elseif (
792
792
!$ app ['config ' ]->get ('debugbar.inject ' , true ) ||
793
- ($ response ->headers ->has ('Content-Type ' ) &&
794
- strpos ($ response ->headers ->get ('Content-Type ' ), 'html ' ) === false ) ||
793
+ strpos ((string ) $ response ->headers ->get ('Content-Type ' ), 'html ' ) === false ||
795
794
$ request ->getRequestFormat () !== 'html ' ||
796
795
$ response ->getContent () === false ||
797
- $ this ->isJsonRequest ($ request )
796
+ $ this ->isJsonRequest ($ request ) ||
797
+ $ this ->isJsonResponse ($ response )
798
798
) {
799
799
try {
800
800
// Just collect + store data, don't inject it.
@@ -862,6 +862,32 @@ protected function isJsonRequest(Request $request)
862
862
return (isset ($ acceptable [0 ]) && $ acceptable [0 ] == 'application/json ' );
863
863
}
864
864
865
+ /**
866
+ * @param \Symfony\Component\HttpFoundation\Response $response
867
+ * @return bool
868
+ */
869
+ protected function isJsonResponse (Response $ response )
870
+ {
871
+ if ($ response ->headers ->get ('Content-Type ' ) == 'application/json ' ) {
872
+ return true ;
873
+ }
874
+
875
+ try {
876
+ $ content = $ response ->getContent ();
877
+
878
+ if (is_string ($ content )) {
879
+ $ content = json_decode ($ content , true );
880
+ }
881
+
882
+ if (is_array ($ content )) {
883
+ return true ;
884
+ }
885
+ } catch (Exception $ e ) {
886
+ }
887
+
888
+ return false ;
889
+ }
890
+
865
891
/**
866
892
* Collects the data from the collectors
867
893
*
0 commit comments