Disable profiler when creating screenshots
tacman opened this issue · comments
Description
I can't imagine that anyone would want to see the debug toolbar in the screenshots they're creating.
It can be disabled programmatically:
Example
No response
I think an event subscriber like as follows should do the job.
Not tested, but basically it disables the profiler if avaialble and if the user agent contains a specific keyword
<?php
namespace App\EventSubscriber;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Profiler\Profiler;
final readonly class MySubscriber implements EventSubscriberInterface
{
public function __construct(
#[Autowire(service: 'profiler')]
private ?Profiler $profiler = null
){}
public static function getSubscribedEvents(): array
{
return [
'kernel.request' => 'onKernelRequest',
];
}
public function onKernelRequest(RequestEvent $event): void
{
if ($this->profiler === null) {
return;
}
$userAgent = $event->getRequest()->headers->get('user-agent');
if ($userAgent === null || !str_contains($userAgent, 'xxxxxxx')) { // <= PUT THE USER-AGENT KEYWORD HERE
return;
}
$this->profiler->disable();
}
}
Great idea. Then the pwa:create:screenshots will set a user-agent?
It looks like it is possible. The user-agent is set to something something HeadelessChrome/something
, which is already a clue.
use Facebook\WebDriver\WebDriverCapabilityType;
$customUserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) PWABundle/123.0.0.0 Safari/537.36';
$client = static::createPantherClient([
'capabilities' => [
WebDriverCapabilityType::CHROME => [
'args' => ["--user-agent={$customUserAgent}"],
],
],
]);
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.