nunomaduro / laravel-console-dusk

Laravel Console Dusk allows the usage of Laravel Dusk in Laravel/Laravel Zero artisan commands.
MIT License
151 stars 22 forks source link

Question: Change User Agent during Runtime / execute command #36

Open pboese opened 8 months ago

pboese commented 8 months ago

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 commented 8 months ago

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 :-(