rialto-php / puphpeteer

A Puppeteer bridge for PHP, supporting the entire API.
MIT License
1.34k stars 205 forks source link

How to set cookies? #178

Open muleyo opened 2 years ago

muleyo commented 2 years ago

Hello,

I'm trying to set cookies with $page->setCookies(file_get_contents("cookies.json")); but unfortunately, I get an error:

Fatal error: Uncaught Nesk\Rialto\Exceptions\Node\FatalException: Protocol error (Network.deleteCookies): Invalid parameters Failed to deserialize params.name - BINDINGS: mandatory field missing at position 11580 in /var/www/panel/vendor/nesk/rialto/src/ProcessSupervisor.php:307 Stack trace: #0 /var/www/panel/vendor/nesk/rialto/src/ProcessSupervisor.php(387): Nesk\Rialto\ProcessSupervisor->checkProcessStatus() #1 /var/www/panel/vendor/nesk/rialto/src/Traits/CommunicatesWithProcessSupervisor.php(84): Nesk\Rialto\ProcessSupervisor->executeInstruction(Object(Nesk\Rialto\Instruction)) #2 /var/www/panel/vendor/nesk/rialto/src/Traits/CommunicatesWithProcessSupervisor.php(100): Nesk\Rialto\Data\BasicResource->proxyAction('call', 'setCookie', Array) #3 /var/www/panel/test.php(27): Nesk\Rialto\Data\BasicResource->__call('setCookie', Array) #4 {main} thrown in /var/www/panel/vendor/nesk/rialto/src/ProcessSupervisor.php on line 307

The same happens if I try $page->setCookies(json_decode(file_get_contents("cookies.json")));

sundayj-1213 commented 2 years ago

You are passing a string to the function, convert the string to an array, then it should work

$cookies = json_decode(file_get_contents("cookies.json")); $page->setCookies(...$cookies);