rialto-php / puphpeteer

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

How to use Network.enable #133

Closed popouille closed 3 years ago

popouille commented 3 years ago

Hello, i trying to implement the following code in the puphpeteer way :

await page._client.send('Network.enable', {
      maxResourceBufferSize: 1024 * 1204 * 100,
      maxTotalBufferSize: 1024 * 1204 * 200,
    })

i tested: $page->_client->send('Network.enable', ['maxResourceBufferSize '=> 1024 * 1204 * 100, 'maxTotalBufferSize' => 1024 * 1204 * 200]);

But i got this error:

Page._client is not a function

I can't figure out with the current documentation how to do it.

nesk commented 3 years ago

This is an undocumented property so I can't tell when it was added to Puppeteer. However, my guess is that the property is not available in the version used by PuPHPeteer (Puppeteer 5.5 if you use the latest version of PuPHPeteer).

nesk commented 3 years ago

Well, I've just tried, it works:

❯ psysh
Psy Shell v0.10.5 (PHP 7.4.13 — cli) by Justin Hileman
New version is available (current: v0.10.5, latest: v0.10.6)
>>> $pu = new Nesk\Puphpeteer\Puppeteer()
=> Nesk\Puphpeteer\Puppeteer {#2580}
>>> $br = $pu->launch()
=> Nesk\Puphpeteer\Resources\Browser {#2578}
>>> $pa = $br->newPage()
=> Nesk\Puphpeteer\Resources\Page {#2594}
>>> $pa->_client
=> Nesk\Puphpeteer\Resources\CDPSession {#2596}
>>>

Just update to the latest version of PuPHPeteer, run npm update to also update the Puppeteer version used, and it should work :)