Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CdpPage.querySelector is not a function #11

Open
1 of 3 tasks
meyer59 opened this issue Apr 1, 2024 · 3 comments
Open
1 of 3 tasks

CdpPage.querySelector is not a function #11

meyer59 opened this issue Apr 1, 2024 · 3 comments

Comments

@meyer59
Copy link

meyer59 commented Apr 1, 2024

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)
klkvsk added a commit to klkvsk/puphpeteer that referenced this issue May 9, 2024
@xtrime-ru
Copy link
Member

xtrime-ru commented Jul 10, 2024

Thanks for report!
Please send PR, i will accept it, looks safe.

Maybe its some issues with windows or with dependencies. Never had such issue.

mreiden added a commit to mreiden/puphpeteer that referenced this issue Aug 21, 2024
 - Update requirements to PHP 8.3, Node 18.0, puppeteer 22
 - Use relative paths for .mjs imports and no longer require node packages
 - Remove Frame->ExecutionContext() [Puppeteer v17]
 - Rename Page->createIncognitoBrowserContext() to Page->createBrowserContext() [Puppeteer v22]
 - Remove CDP (case-insensitve) from puppeteer classes in responses (CdpBrowser, etc) [Solves zoonru#8 and zoonru#11]
 - Add PHP strict_types declarations
 - Update phpunit to 11.3 fix tests to run
@Raja-Omer-Mustafa
Copy link

#15
@xtrime-ru

@xtrime-ru
Copy link
Member

Made a new release, please check, if issue exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants