mirasvit / module-profiler

Magento 2 Profiler
https://mirasvit.com/
Open Software License 3.0
133 stars 36 forks source link

Do not append profiling block when "Content-Type: application/json" response header is set #6

Closed heldchen closed 7 years ago

heldchen commented 8 years ago

some extension (Magme WebForms Pro 2) use an iframe to post form data and get json back. unfortunately, Mirasvit_Profiler then appends its profiling block to the result, breaking the javascript execution.

could the extension check if a response header with content-type "application/json" is set and then not output the block?

heldchen commented 8 years ago

turns out its pretty simple to achieve, please see the following patch:

diff --git a/www/vendor/mirasvit/module-profiler/src/Profiler/Block/Container.php b/www/vendor/mirasvit/module-profiler/src/Profiler/Block/Container.php
index 505e983..b2a59a7 100644
--- a/www/vendor/mirasvit/module-profiler/src/Profiler/Block/Container.php
+++ b/www/vendor/mirasvit/module-profiler/src/Profiler/Block/Container.php
@@ -63,4 +63,20 @@ class Container extends Template
     {
         return $this->context->getDbProfiler()->getTotalElapsedSecs();
     }
+
+    /**
+     * @return string
+     */
+    protected function _toHtml()
+    {
+        foreach (headers_list() as $header)
+        {
+            if (stripos($header, 'Content-type') !== FALSE) {
+                if ((strpos($header, 'json') !== FALSE) || (strpos($header, 'xml') !== FALSE))
+                    return '';
+            }
+        }
+
+        return parent::_toHtml();
+    }
 }
heldchen commented 7 years ago

has this been fixed in the code? haven't seen a commit related to this, maybe missed it tho...