CdpPage.querySelector is not a function
meyer59 opened this issue · comments
Describe the bug
"__rialto_error__":true,"message":"Error: CdpPage.querySelector is not a function
When retrieving a browser instance, the querySelector
method is not found.
As i can see the launch()
method return a BasicResource
instead of a Page
which contains those methods.
It seems like the same bug as #8 which has been closed without helping infos.
Reproducible example
use Nesk\Puphpeteer\Puppeteer;
$options = [
'args' => [
'--no-sandbox',
'--disable-web-security',
'--disable-setuid-sandbox',
'--allow-file-access-from-files',
'--disk-cache-dir="C:\\Users\\meyer\\.cache\\puppeteer"'
],
'log_browser_console' => true,
'log_node_console' => false,
'debug' => false,
];
$puppeteer = new Puppeteer($options);
$browser = $puppeteer->launch([
'headless' => 'new',
'defaultViewport' => ['width' => 1920, 'height' => 1080],
]);
$page = $browser->newPage();
$page->goto('https://laravel.com/docs/10.x/helpers#available-methods');
$page->querySelector("#available-methods"); //error is here
One potential fix that i found is that the regex which replace the CDP namespace should be ignoring the Case so the right class is called.
In: vendor/zoon/puphpeteer/src/PuppeteerProcessDelegate.php
Adding a i
in the preg_replace('/^CDP/i', '', $className);
seems to fix the issue. I can PR the fix, but since my knowledge of the package is limited i'm waiting for a confirmation from you end.
Environment (please complete the following information):
-Windows 10,
- Node version: v20.11.1
- PHP version 8.2
My Node package manager is:
- NPM (10.2.4)
- Yarn (specify the version)
- Other (specify the name and version)