始终在开发模式下显示工具栏

I want to always display the toolbar in dev mode, not only on errors. I have the following method:

/**
 * @Route("/", name="homepage")
 */
public function indexAction(Request $request) : JsonResponse
{
    return new JsonResponse($param);
}

that I run to test the toolbar. This generates an error of course because $param and the toolbar appears. But when I use return new JsonResponse('aaa'); everything works and the toolbar does not appear.

How to make the toolbar appread even without errors?

config:

framework:
    templating:
        engines: ['twig']
    router:
        resource: "%kernel.root_dir%/config/dev/routing.yml"
        strict_requirements: true
    profiler: { only_exceptions: false }

web_profiler:
    toolbar: true
    intercept_redirects: true

AppKernel:

if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
            $bundles[] = new Symfony\Bundle\TwigBundle\TwigBundle();
}

Symfony injects the toolbar only in certain conditions, and only if the response is an html response. See the WebDebugToolbarListener to learn how it's done. The listener looks for the </body> tag and injects the toolbar code before it.

If the listener injected the toolbar into a json response, it would make the response invalid.

You can still access the profile though, as the profiler link is included in the X-Debug-Token-Link header of the response. You can also find the profiler unique identifier in the X-Debug-Token header.

Note that the X-Debug-Token-Link header was introduced in Symfony 2.4. Before you could only access the token.