My profiler toolbar isn't showing up in symfony 4.3.1
Asked Answered
B

7

23

In my .env file, I have specified my app environment to be dev and debug to be true like so:

APP_ENV=dev
APP_DEBUG=true

In my config/packages/dev/web_profiler.yaml file I have the following:

web_profiler:
    toolbar: true
    intercept_redirects: false

framework:
    profiler: { only_exceptions: false }

The routing within config/routes/dev/web_profiler.yaml seems to be fine:

web_profiler_wdt:
    resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
    prefix: /_wdt

web_profiler_profiler:
    resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
    prefix: /_profiler

So when I run the server with symfony server:start everything is fine, but the profiler doesn't appear. Did I miss something that enables that feature within Symfony?

To clarify, the page is outputting a proper HTML page with the appropriate content. There is just no profiler showing up.


My base twig template:

<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8">
        <title>{% block title %} {% endblock %}</title>
        {{ encore_entry_script_tags('base') }}
        <link rel="icon" type="image/x-icon" href="{{ asset('build/images/favicon.ico') }}" />
        <link href="https://fonts.googleapis.com/css?family=IBM+Plex+Sans:400,500|Playfair+Display:400,700&display=swap" rel="stylesheet">
        {{ encore_entry_link_tags("base") }}
        {% block stylesheet %}{% endblock %}
    </head>
    <body {% if app.request.get('_route') == 'home' %} class='homepage' {% endif %} >
        <header>
            <div id='top-navigation' class='padding-lg__left-md padding-lg__right-md padding-lg__top-sm padding-lg__bottom-sm row row__align-center row__justify-start'>
                <span class='text-color__white text-size__small text-weight__bold margin-lg__right-lg'>Our Mission</span>
                <span class='text-color__white text-size__small text-weight__bold margin-lg__right-lg'>Our Team</span>
                <span class='text-color__white text-size__small text-weight__bold margin-lg__right-lg'>Where the Money Goes</span>
                <span class='text-color__white text-size__small text-weight__bold margin-lg__right-lg'>Community Leadership</span>
                <span class='text-color__white text-size__small text-weight__bold'>Policies</span>
                <span class='text-color__white text-size__small text-weight__bold margin-lg__left-auto icon-set'> <span class='icon size__small color__white margin-lg__right-xsm'>{{ source('@public_path'~asset('build/images/icons/feedback.svg')) }}</span>Submit Feedback</span>
            </div>
            <nav class="padding-lg__top-md padding-lg__bottom-md padding-lg__left-md padding-lg__right-md row row__align-center row__justify-start {% if app.request.get('_route') == 'home' %} homepage {% endif %}">
                <div id='logo'>
                    <a href="{{ url('home') }}">
                        <img src="{{ asset('build/images/logo_placeholder.png') }}" alt="logo">
                    </a>
                </div>
                {% if app.request.get('_route') == 'creator-register' %}

                {% else %}
                    {% if not is_granted('IS_AUTHENTICATED_FULLY') %}
                        <div class='margin-lg__left-auto'>
                            <a href="{{ url('login') }}">
                                <div class='icon-set'>
                                    <span class='icon margin-lg__right-xsm'>
                                        {{ source('@public_path'~asset('build/images/icons/user.svg')) }}
                                    </span>
                                    <span class='nav-item'>Login</span>
                                </div>
                            </a>
                        </div>
                    {% endif %}

                {% endif %}
            </nav>
        </header>
        {% if app.request.get('_route') != 'home' %} <div class='container is_top'> {% endif %}
            {% block body %} {% endblock %}
        {% if app.request.get('_route') != 'home' %} </div> {% endif %}
    </body>
</html>

Security.yaml firewall:

    firewalls:
            dev:
                pattern: ^/(_(profiler|wdt)|css|images|js)/
                security: false
            main:
                anonymous: true
                guard:
                    authenticators:
                        - App\Security\LoginFormAuthenticator
                logout:
                    path : logout
                remember_me:
                    secret: '%kernel.secret%'
                    lifetime: 2592000 #<- 30 days in seconds - defaults to one year if you take this out!

Results on php bin/console debug:router | grep _profiler:

  _profiler_home             ANY      ANY      ANY    /_profiler/                        
  _profiler_search           ANY      ANY      ANY    /_profiler/search                  
  _profiler_search_bar       ANY      ANY      ANY    /_profiler/search_bar              
  _profiler_phpinfo          ANY      ANY      ANY    /_profiler/phpinfo                 
  _profiler_search_results   ANY      ANY      ANY    /_profiler/{token}/search/results  
  _profiler_open_file        ANY      ANY      ANY    /_profiler/open                    
  _profiler                  ANY      ANY      ANY    /_profiler/{token}                 
  _profiler_router           ANY      ANY      ANY    /_profiler/{token}/router          
  _profiler_exception        ANY      ANY      ANY    /_profiler/{token}/exception       
  _profiler_exception_css    ANY      ANY      ANY    /_profiler/{token}/exception.css 

Lastly homepage controller:

<?php
namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class HomepageController extends AbstractController{

    /**
    * @Route("/", name="home")
    */

    public function output(){
        return $this->render('homepage/home.html.twig',[
            'title' => 'yo',
        ]);
    }
}

?>

Added public/index.php:

<?php

use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;

require dirname(__DIR__).'/config/bootstrap.php';

if ($_SERVER['APP_DEBUG']) {
    umask(0000);

    Debug::enable();
}

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
    Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}

if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
    Request::setTrustedHosts([$trustedHosts]);
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
Barnie answered 28/10, 2019 at 15:35 Comment(40)
Do a ctrl-u in your browser and verify that you have a html page showing up. The bar will only be present for an actual page.Amative
I do have an HTML page, it's showing what the page needs to show, just no profilerBarnie
Can you access the route /_profiler ? does it work ?Hydromancy
@DylanKas I can. It does work!Barnie
Have you checked if you have a small icon at the bottom right of your page ? Clicking it would expand the toolbar, also if there is no icon can you show us your twig layout ?Hydromancy
There is no icon. I'll update the question with the twig base template.Barnie
Nothing wrong with your config. You have installed the profiler, right? If not run composer require --dev symfony/profiler-packManque
I did... It's already installed. I can access the _profiler route tooBarnie
Did you try that ? Because since Symfony 4 you need the whole profiler package composer require profiler —devAngelinaangeline
1. can you check in your browser's network tab (F12 in ff and chrome), that maybe some _profiler route is loaded? (if yes, it's loaded but invisible). 2. is the web profiler bundle active, run bin/console debug:event-dispatcher kernel.response where with -128 priority there should be the WebDebugToolbarListener::onKernelResponse. if it's not, check config/bundles.php, which should contain WebProfilerBundle. yeah.Fiester
@Fiester It looks like the profiler route isn't loading. But I did check the debug and found that it is in the config/bundles.php file. It's just not loading it seems.Barnie
this would suggest, that some condition in WebDebugToolbarListener::onKernelResponse prevents the toolbar from being injected (usually, the </body> is replaced (see: github.com/symfony/symfony/blob/…) Sooo ... I would suggest, you add some dd(true) lines before each return to see which condition triggers the early return, meaning you go in vendor/symfony/web-profiler-bundle/EventListener/WebDebugToolbarListener.php to debug. or use a debugging tool.Fiester
@Fiester I went into the WebDebugToolbarListener.php file and dd() function didn't fire at all in any of the return parts. Maybe that file isn't being called?Barnie
that does indeed sound very weird. then my next approach would be to check if any of the kernel.response event listeners is even working (add dd() to the one with highest priority) and if none is triggered ... well, that would even be weirder .... and if it triggers, some listener has to be the last working.Fiester
Tried the dd(true); on Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse() and it worked on that (that's the highest priority).Barnie
as said, try to find the last one that works, because some Listener probably interrupts the propagation/event-listener-processing ... and take a closer look at that one.Fiester
I found that this is where the WebDebugToolbarListener fails is here on line 102: if (self::DISABLED === $this->mode || !$response->headers->has('X-Debug-Token') || $response->isRedirection() || ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html')) || 'html' !== $request->getRequestFormat() || false !== stripos($response->headers->get('Content-Disposition'), 'attachment;') ) { return; }Barnie
I had a similar issue when upgrading Symfony from 4.2 to 4.3. Check in composer.json if all relevant bundles have the same version like symfony/framework-bundle. Look for symfony/twig-bundle, symfony/yaml and other bundles from symfony.Okwu
@Majo0od if you found that the conditions in line 102 cause the listener to stop working, what have you tried to get that further? Which one of these conditions evaluates to true?Preteritive
Might sound dumb but have you done a clean composer install and a clear cache(composer, symfony and browser)?Intertidal
@NicoHaase It looks like there is no X-Debug-Token - everything else checks out!Barnie
@Majo0od then have a look where that token is set - as far as I see, \Symfony\Component\HttpKernel\Profiler\Profiler::collect is responsible for that. Additionally, it would help if you crafted a reproducable setup for this problem such that others could also see the rest of your configurationPreteritive
Yeah Im not sure how to do that... thus why the question was asked to begin with :)Barnie
Please update your question with a simple controller test (including Annotations) and security.yml firewall rules.Hermineherminia
Also please update the question with the result from php bin/console debug:router | grep _profilerHermineherminia
Added all the following.Barnie
Include the contents of your public/index.php file. By any chance, did you upgrade this project from a previous Symfony version?Limicolous
It was always on 4.X - and uploaded public/index.phpBarnie
@Majo0od Can you add a die('here'); statement right after Debug::enable() on index.php, to verify you are going through there? Also, if you do not ping me, I'm not notified of your replies.Limicolous
Are you sure your application is running on dev env? Can you try var_dump($_SERVER['APP_ENV'], $_SERVER['APP_DEBUG']); in index.php?Glossitis
@Limicolous the die('here'); gets triggered.Barnie
@Glossitis it returns string(3) "dev" string(1) "1"Barnie
How did you install the WebProfilerBundle? Did you execute composer require profiler --dev, or something else?Limicolous
Temporally modify WebDebugToolbarListener.php. On line 109 add this before the return statement: echo 'Mode: ', $this->mode, " XDebTok: ", $response->headers->has('X-Debug-Token'), " IsRedir: ", $response->isRedirection(); die(); and report the return for that.Limicolous
@Limicolous I executed using the composer the way you showed it. Let me try the die statement within the line 109.Barnie
@Limicolous It returned Mode: 2 XDebTok: IsRedir:Barnie
See this is what I'm talking about. I don't know what the mode references. I do know that the X Debug Token is necessary to make the profiler function (it's what stores data) - as for the redirection, there is none at this point (assuming it means going to and from the profiler?)Barnie
The debug token is missing, for some reason.Limicolous
@Limicolous so.... how do I get it back? This is bizarre because it was working one day, then all of a sudden it stopped. Is the X Debug Token a cookie? Maybe that's the issue here? Maybe I accidentally deleted it?Barnie
Add some bogus string(e.g. "abc") at the top of "config/packages/dev/web_profiler.yaml" to see if you get an error. Maybe the file is not read at all.Brownson
L
30

It's very hard, if not impossible, to debug this for you remotely. The exact problem is tied to something specific in your local setup, and someone without access to your project would not have a chance to see exactly what is wrong.

Some general and specific troubleshooting advice for your situation:

1st. Reinstall the profiler pack

While unusual, the installation could be borked. Make sure your profiler package is alright.

First remove it (composer remove profiler), and then install it again: composer require --dev profiler).

2nd. Check the configuration

Use Symfony's console command to verify your configuration.

First for the built-in profiler:

$ bin/console debug:config framework profiler

Which should return something like this:

Current configuration for "framework.profiler"
==============================================

only_exceptions: false
enabled: true
collect: true
only_master_requests: false
dsn: 'file:%kernel.cache_dir%/profiler'

And then for the profiler toolbar:

$ bin/console debug:config web_profiler

Which should return something like:

Current configuration for extension with alias "web_profiler"
=============================================================

web_profiler:
    toolbar: true
    intercept_redirects: false
    excluded_ajax_paths: '^/((index|app(_[\w]+)?)\.php/)?_wdt'

3rd. Check the container

Check how the Profiler service will be instantiated:

$ bin/console debug:container profiler --show-arguments

Expect something like this:

Information for Service "profiler"
==================================

 Profiler.

 ---------------- -------------------------------------------------------------------------------------
  Option           Value
 ---------------- -------------------------------------------------------------------------------------
  Service ID       profiler
  Class            Symfony\Component\HttpKernel\Profiler\Profiler
  Tags             monolog.logger (channel: profiler)
                   kernel.reset (method: reset)
  Calls            add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add
  Public           yes
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        no
  Autoconfigured   no
  Arguments        Service(profiler.storage)
                   Service(monolog.logger.profiler)
                   1
 ---------------- -------------------------------------------------------------------------------------

And then for the web_toolbar:

# bin/console debug:container web_profiler.debug_toolbar --show-arguments

For something like this:

Information for Service "web_profiler.debug_toolbar"
====================================================

 WebDebugToolbarListener injects the Web Debug Toolbar.

 ---------------- ------------------------------------------------------------------------
  Option           Value
 ---------------- ------------------------------------------------------------------------
  Service ID       web_profiler.debug_toolbar
  Class            Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener
  Tags             kernel.event_subscriber
                   container.hot_path
  Public           no
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        no
  Autoconfigured   no
  Arguments        Service(twig)

                   2
                   Service(router.default)
                   ^/((index|app(_[\w]+)?)\.php/)?_wdt
                   Service(web_profiler.csp.handler)
 ---------------- ------------------------------------------------------------------------

(Note the 2, which enables the toolbar).

4th. Check the event dispatcher.

The web debug toolbar is injected during the kernel.response event. Check that the callback is appropriately hooked:

$ bin/console debug:event-dispatcher kernel.response

Which will return something like this:

Registered Listeners for "kernel.response" Event
================================================

 ------- -------------------------------------------------------------------------------------------- ----------
  Order   Callable                                                                                     Priority
 ------- -------------------------------------------------------------------------------------------- ----------
  #1      ApiPlatform\Core\Hydra\EventListener\AddLinkHeaderListener::onKernelResponse()               0
  #2      Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse()              0
  #3      Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelResponse()          0
  #4      Symfony\Component\WebLink\EventListener\AddLinkHeaderListener::onKernelResponse()            0
  #5      Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse()              0
  #6      ApiPlatform\Core\HttpCache\EventListener\AddHeadersListener::onKernelResponse()              -1
  #7      Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse()              -100
  #8      Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse()   -128
  #9      Symfony\Component\HttpKernel\EventListener\TestSessionListener::onKernelResponse()           -128
  #10     Symfony\Component\HttpKernel\EventListener\DisallowRobotsIndexingListener::onResponse()      -255
  #11     Symfony\Component\HttpKernel\EventListener\SessionListener::onKernelResponse()               -1000
  #12     Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse()      -1024
 ------- -------------------------------------------------------------------------------------------- ----------

Notice item #7, which is the Profiler collector (which among other things will include the X-Debug-Token header in the response, which will be later checked by the Web Debug Toolbar, which is item #8 in the above listing.

If any of the above checks fails

You'll have to focus on that specific part to find out why it is failing. Maybe some other bundle interfering? A problem with one of the configuration files?

Everything checks out

... but still not working? Well, that's weird. Make sure that your returned template has a </body> tag, and that the returned response has text/html content-type. But if all of the above checks out... it should work.


In a comment you say that framework.profiler.collect is set to false when performing these checks.

Set it to true by changing config/packages/dev/web_profiler.yaml like this:

framework:
    profiler:
        only_exceptions: false
        collect: true
Limicolous answered 14/11, 2019 at 9:50 Comment(5)
The thing that stood out was: debug:config framework profiler returned collect: falseBarnie
So try adding the configuration of framework.profiler.collect so it says true.Limicolous
ITS ALIVE!!! Finally! It has now come back! Thank you for all of the debugging and help!!!!Barnie
Who knew a single line could mess everything up. Historically we didn't need to add collect : true if I remember correctly? Is this new?Barnie
Thanks for all these steps! Turned out I created a template that didn't extend base so wasn't actually returning HTML/Javascript but only plaintext.Flatworm
R
9

I had this problem too. I'm new to Sympfony, and I didn't knew, that .htaccess must be required via composer, if running on apache. Simply doing this:

composer require symfony/apache-pack

was the solution.

Rudimentary answered 13/2, 2021 at 10:46 Comment(1)
More than an hour trying to figure out why only root (/) route working in my local environment. This composer require did the trick for my. Now all routes, including the /_profiler/* ones, are working. Thanks!Barneybarnhart
C
5

I had a similar symptom in a new Symfony 5.1 app - debug toolbar not displaying on some pages even though the project was in debug mode. Turned out in this app I had intended to have the <body></body> tags inside the twig template for each page, and not in the base template. But for a few pages (those that didn't display the debug toolbar), I had forgotten to include the <body></body> tags in the page template, so the rendered HTML had no <body> tag - hence debug toolbar will not display.

Crosby answered 25/9, 2020 at 21:6 Comment(1)
thank you - I had the same issue. was wondering why the toolbar was not displayed. And I also had no body but only a head defined. therefore the toolbar was not showing.Ridiculous
B
1

This can also happen when accessing your local site through HTTP instead of HTTPS, which can make the toolbar request fail.

Check by looking at the request tab of the browser dev tools. If requests are blocked, you might miss a proxy configuration (from this issue):

framework:
    trusted_proxies: '127.0.0.1,REMOTE_ADDR'
Boyd answered 19/5, 2021 at 12:53 Comment(3)
This is my case. Did you solve this issue, while keeping the HTTPS local URL?Gastineau
@LoïcPennamen Not sure if I understand. I just made sure to access the local site trough https and it works for me.Boyd
@LoïcPennamen see the edit I made to this answer.Diagenesis
B
0

If you keeps getting a "loading..." message (or something similar), check the authentication works correctly.

Migrating from the old Guard System to the new Security System I broke the authentication mechanism (and also the handling of anonymous users) and this caused the debug toolbar not being loaded.

Baeza answered 12/1, 2022 at 17:47 Comment(0)
C
0

In case you are using Apache instead of the Symfony Server, in the first place you must install the Apache pack:

composer require symfony/apache-pack

In the second place, make sure Apache mod_rewrite is enabled. In Debian or Debian like OS you can do it this way:

sudo a2enmod rewrite

Finally, allow overrides in Apache editing apache2.conf, for instance:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

Notice "AllowOverride All" instead of "AllowOverride None"

Communicative answered 1/11, 2023 at 16:22 Comment(0)
M
-1

Try to use the command:

composer dump-env dev
Marten answered 17/3, 2021 at 9:10 Comment(1)
Please add some explanation to your answer such that others can learn from it. Why does that resolve the problem?Preteritive

© 2022 - 2024 — McMap. All rights reserved.