laravel-console-dusk icon indicating copy to clipboard operation
laravel-console-dusk copied to clipboard

Question: Change User Agent during Runtime / execute command

Open pboese opened this issue 11 months ago • 1 comments

Heya,

first I wanted to thank you for this awesome package, it really helps a lot!

For a very specific use case I need to change the user agent of the local chrome browser during runtime. I found https://stackoverflow.com/questions/67077671/how-to-change-at-runtime-the-user-agent-of-a-remote-selenium-driver but I have no clue how to run execute (execute_cdp_command) in Laravel. Is there a way to achieve this?

Thanks a lot for any help,

Pelle

pboese avatar Mar 12 '24 08:03 pboese

Update: There is a way in theory, e.g.

$browser->browser->driver->executeCustomCommand(
    '/session/:sessionId/goog/cdp/execute',
    'POST',
    ['cmd' => 'Network.setUserAgentOverride', 'params' => ['userAgent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36']],
);

In reality it does not work because $browser is protected in NunoMaduro\LaravelConsoleDusk\ConsoleBrowser :-(

pboese avatar Mar 12 '24 08:03 pboese