Skip to content

[WebProfilerBundle] Add configuration entry to disable JS confirm dialog on error #23251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function getConfigTreeBuilder()
->end()
->end()
->booleanNode('intercept_redirects')->defaultFalse()->end()
->booleanNode('show_error_confirmation')->defaultTrue()->end()
->scalarNode('excluded_ajax_paths')->defaultValue('^/(app(_[\\w]+)?\\.php/)?_wdt')->end()
->end()
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public function load(array $configs, ContainerBuilder $container)

if ($config['toolbar'] || $config['intercept_redirects']) {
$loader->load('toolbar.xml');
$container->getDefinition('web_profiler.debug_toolbar')->replaceArgument(5, $config['excluded_ajax_paths']);
$container->getDefinition('web_profiler.debug_toolbar')
->replaceArgument(5, $config['excluded_ajax_paths'])
->addMethodCall('setShowErrorConfirmation', array($config['show_error_confirmation']));

$container->setParameter('web_profiler.debug_toolbar.intercept_redirects', $config['intercept_redirects']);
$container->setParameter('web_profiler.debug_toolbar.mode', $config['toolbar'] ? WebDebugToolbarListener::ENABLED : WebDebugToolbarListener::DISABLED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface
protected $mode;
protected $position;
protected $excludedAjaxPaths;
protected $showErrorConfirmation = true;
private $cspHandler;

public function __construct(Environment $twig, $interceptRedirects = false, $mode = self::ENABLED, $position = 'bottom', UrlGeneratorInterface $urlGenerator = null, $excludedAjaxPaths = '^/bundles|^/_wdt', ContentSecurityPolicyHandler $cspHandler = null)
Expand All @@ -60,6 +61,11 @@ public function isEnabled()
return self::DISABLED !== $this->mode;
}

public function setShowErrorConfirmation($showErrorConfirmation)
{
$this->showErrorConfirmation = (bool) $showErrorConfirmation;
}

public function onKernelResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
Expand Down Expand Up @@ -130,6 +136,7 @@ protected function injectToolbar(Response $response, Request $request, array $no
'request' => $request,
'csp_script_nonce' => isset($nonces['csp_script_nonce']) ? $nonces['csp_script_nonce'] : null,
'csp_style_nonce' => isset($nonces['csp_style_nonce']) ? $nonces['csp_style_nonce'] : null,
'show_error_confirmation' => $this->showErrorConfirmation,
)
))."\n";
$content = substr($content, 0, $pos).$toolbar.substr($content, $pos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<xsd:complexType name="config">
<xsd:attribute name="toolbar" type="xsd:boolean" />
<xsd:attribute name="intercept-redirects" type="xsd:boolean" />
<xsd:attribute name="show-error-confirmation" type="xsd:boolean" />
<xsd:attribute name="position" type="positions" />
</xsd:complexType>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
});
},
function(xhr) {
if (xhr.status !== 0) {
if (xhr.status !== 0 && {{ show_error_confirmation ? 'true' : 'false' }}) {
confirm('An error occurred while loading the web debug toolbar (' + xhr.status + ': ' + xhr.statusText + ').\n\nDo you want to open the profiler?') && (window.location = '{{ path("_profiler", { "token": token }) }}');
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ public function testConfigTree($options, $results)
public function getDebugModes()
{
return array(
array(array(), array('intercept_redirects' => false, 'toolbar' => false, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('intercept_redirects' => true), array('intercept_redirects' => true, 'toolbar' => false, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('intercept_redirects' => false), array('intercept_redirects' => false, 'toolbar' => false, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('toolbar' => true), array('intercept_redirects' => false, 'toolbar' => true, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('position' => 'top'), array('intercept_redirects' => false, 'toolbar' => false, 'position' => 'top', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('excluded_ajax_paths' => 'test'), array('intercept_redirects' => false, 'toolbar' => false, 'position' => 'bottom', 'excluded_ajax_paths' => 'test')),
array(array(), array('intercept_redirects' => false, 'toolbar' => false, 'show_error_confirmation' => true, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('intercept_redirects' => true), array('intercept_redirects' => true, 'toolbar' => false, 'show_error_confirmation' => true, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('intercept_redirects' => false), array('intercept_redirects' => false, 'toolbar' => false, 'show_error_confirmation' => true, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('show_error_confirmation' => true), array('intercept_redirects' => false, 'toolbar' => false, 'show_error_confirmation' => true, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('show_error_confirmation' => false), array('intercept_redirects' => false, 'toolbar' => false, 'show_error_confirmation' => false, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('toolbar' => true), array('intercept_redirects' => false, 'toolbar' => true, 'show_error_confirmation' => true, 'position' => 'bottom', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('position' => 'top'), array('intercept_redirects' => false, 'toolbar' => false, 'show_error_confirmation' => true, 'position' => 'top', 'excluded_ajax_paths' => '^/(app(_[\\w]+)?\\.php/)?_wdt')),
array(array('excluded_ajax_paths' => 'test'), array('intercept_redirects' => false, 'toolbar' => false, 'show_error_confirmation' => true, 'position' => 'bottom', 'excluded_ajax_paths' => 'test')),
);
}
}