framework: New Version of Chrome cannot render dd function in network preview window

  • Laravel Version: 5.4.* and 5.5.*
  • PHP Version: 7.0.13
  • Database Driver & Version: Mysql 5.6

Description:

When updated to chrome version 62.0.3202.66, dd function cannot be rendered by chrome network preview window.

fzr n2qqt 1c4hpj wu6a

And I have found the changelog of chrome. Commit f674b40baf2d44d1b27f33b3ed39e60b2b9169da says it will not render as HTML agressively if requested via XHR.

Steps To Reproduce:

  1. Update to chrome version 62.0.3202.66
  2. Execute a dd function
  3. Check the chrome network preview window

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 14
  • Comments: 33 (7 by maintainers)

Most upvoted comments

This function works pretty well for me. Only handles the HTML Dumper, not the CLI dumper, so it wont work in artisan commands, but if you’re using those you can just use the normal dd() function.

function _dd(...$args)
{
    $content = "<!DOCTYPE html><html><body>";

    foreach ($args as $arg) {
        $val = (new \Symfony\Component\VarDumper\Cloner\VarCloner)->cloneVar($arg);
        $dumper = new \Illuminate\Support\Debug\HtmlDumper;
        $content .= $dumper->dump($val, true);
    }

    $content .= "</body></html>";

    return response($content, 500)->header('Content-Type', 'text/html')->send();
}

Yeah, I’ve updated to 68 and it works again, “Sweet sweet preview scroll, never leave me again”

If you want to change status to 500 for your ajax requests you just need to update

project/vendor/symfony/var-dumper/Dumper/HtmlDumper.php class on line 111 where dump() method exists. Just add line http_response_code(500); at the beginning of function. It works for Laravel 5.6 version.

Using die($item) instead of dd($item) on a model renders the json in the network tab same as a json response. The object have to implement __toString() though.

@tonghia I tested after adding <html></html> tag, it also doesn’t work. @alinasiri1367 there are some approaches to solve it in this issue