Coder Social home page Coder Social logo

Comments (23)

nesk avatar nesk commented on May 20, 2024 2

Version 0.2.2 is now available and supports Puppeteer v1.3+. Additionnally, from now you will be warn in the logs if the installed version of Puppeteer doesn't match the requirements. 😉

Since it should be solved, I'm closing the issue.

from puphpeteer.

egifford avatar egifford commented on May 20, 2024 1

I think you are correct that the Puppeteer version was causing my issue. I did a clean install with composer and npm, made sure I had [email protected], and my screenshot script worked perfectly.

Before I found PuPHPeteer, I was evaluating spatie/browsershot and must have still had a newer version of puppeteer installed.

This project is really good. I hope I didn't take too much of your time to resolve this.

If you decide to setup a project funding mechanism, like Patreon, I'd contribute some USDs. Though it looks like you might have some funding via a startup. Anyway, good luck!

from puphpeteer.

nesk avatar nesk commented on May 20, 2024

Could you please give me a reproducible example?

from puphpeteer.

knvpk avatar knvpk commented on May 20, 2024

Im using this in the laravel project -> commands (console), below is my handle function

        $puppeteer = new Puppeteer([
            'read_timeout' => 100,
            'debug' => env('APP_DEBUG')
        ]);
        $browser = $puppeteer->launch([
            'headless' => env('APP_DEBUG'),
            'ignoreHTTPSErrors' => true
        ]);

        $page = $browser->newPage();
        $page->setViewport(['width' => 1920, 'height' => 1080]);

        // Login first
        $page->goto('http://xxxxxx.in/home.do#', ['waitUntil' => 'networkidle2']);
        $page->type('.loginEmail', env('xxxxxx_USERNAME'));
        $page->type('.loginPassword', env('xxxxx_PASSWORD'));
        $page->click("#login input[type='submit']");
        $page->waitForNavigation();

from puphpeteer.

nesk avatar nesk commented on May 20, 2024

This code doesn't reproduce the error you showed me. Did you try running it independently from all your application?

I've adapted your code to reproduce your issue, here's what I've got:

<?php

require 'vendor/autoload.php';

use ExtractrIo\Puphpeteer\Puppeteer;

$debug = true;

$puppeteer = new Puppeteer([
    'read_timeout' => 100,
    'debug' => $debug,
]);
$browser = $puppeteer->launch([
    'headless' => !$debug,
    'ignoreHTTPSErrors' => true,
]);

$page = $browser->newPage();
$page->setViewport(['width' => 1920, 'height' => 1080]);

$page->goto('https://semantic-ui.com/examples/login.html', ['waitUntil' => 'networkidle2']);
$page->tryCatch->type('[name=email]', '[email protected]');
$page->tryCatch->type('[name=password]', 'thisismypassword');
$page->click('.submit');
$page->waitForNavigation();

Try running it in your environment by copying the code in a test.php file and running php test.php.

from puphpeteer.

egifford avatar egifford commented on May 20, 2024

I think this project is really cool, but I'm getting the same error as the OP.

Here is my configuration:

  • Windows 10 Pro
  • Running in Git for Windows bash (version 2.16.0.windows.2)
  • PHP 7.1.16 (cli) (built: Mar 28 2018 21:15:22) ( NTS MSVC14 (Visual C++ 2015) x64 )
  • Node v8.9.4

I'm using the 0.2.1 version of puphpeteer.

My PHP code is something like this:

$puppeteer = new Puppeteer(['debug' => true]);
$browser   = $puppeteer->launch();

$page = $browser->newPage();
$page->goto('https://example.com');
$page->screenshot(['path' => 'example.png']);

$browser->close();

My code is failing on the call to launch().

Here is the error I receive:

Fatal error: Uncaught ExtractrIo\Rialto\Exceptions\Node\FatalException: Right-hand side of 'instanceof' is not an object

TypeError: Right-hand side of 'instanceof' is not an object
    at PuppeteerConnectionDelegate.handleInstruction (vendor\extractr-io\puphpeteer\src\PuppeteerConnectionDelegate.js:42:19)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7) in vendor\extractr-io\rialto\src\ProcessSupervisor.php:230
Stack trace:
#0 vendor\extractr-io\rialto\src\ProcessSupervisor.php(322): ExtractrIo\Rialto\ProcessSupervisor->checkProcessStatus()
#1 vendor\extractr-io\rialto\src\ProcessSupervisor.php(285): ExtractrIo\Rialto\ProcessSupervisor->readNextProcessValue()
#2 vendor\extractr-io\rialto\src\Traits\CommunicatesWithProcessSupervisor.php(83): ExtractrIo\Rialto\ProcessSupervis in vendor\extractr-io\rialto\src\ProcessSupervisor.php on line 230

Let me know if you need any more information or want me to test something.

Thanks!

EDIT: Debugging a bit... The instruction being sent from PHP to Node is:
{"type":"call","name":"launch","catched":false,"value":[]}

from puphpeteer.

nesk avatar nesk commented on May 20, 2024

Actually, I have a hard time reproducing the issue. Could you edit vendor/extractr-io/puphpeteer/PuppeteerConnectionDelegate.js in your project and add this code in line 41 (provide a valid file path in this code)?

const filePath = '/path/to/a/safe/directory/to/write/debug.txt';
require('fs').writeFileSync(filePath, typeof Browser);
if (Browser && Browser.toString) require('fs').appendFileSync(filePath, '\n\n' + Browser.toString());
require('fs').appendFileSync(filePath, '\n\n' + JSON.stringify(Browser));

Then run (new \ExtractrIo\Puphpeteer\Puppeteer)->launch() in PHP and send me the contents of the generated debug.txt file.

from puphpeteer.

egifford avatar egifford commented on May 20, 2024

Thank you for the clear directions.

Here is the output from debug.txt:

undefined

undefined

As I was adding the debugging code, it occurred to me that the object I'm having trouble with is the Browser object from the puppeteer project. I also noticed that your packages (puphpeteer and rialto) are located in both /vendor and /node_modules.

I'm wondering if my environment is having issues loading modules?

Interestingly, when I open /vendor/extractr-io/puphpeteer/PuppeteerConnectionDelegate.js, my IDE (PHPStorm) shows a red error on the following code for the Browser object and ConnectionDelegate object:

const puppeteer = require('puppeteer'),
    {Browser} = require('puppeteer/lib/Browser'),
    {ConnectionDelegate} = require('@extractr-io/rialto');

When I open /node_modules/@extractr-io/puphpeteer/src/PuppeteerConnectionDelegate.js, my IDE does not show any errors.

Could my node environment be having trouble finding the puppeteer module that is under /node_modules when running PuppeteerConnectionDelegate.js from the /vendor directory.

To test, I changed the constructor in Puppeteer.php to load PuppeteerConnectionDelegate.js from the /node_module directory:

/**
 * Instanciate Puppeteer's entry point.
 */
public function __construct(array $userOptions = [])
{
    $base_dir = __DIR__ . '/../../../../node_modules/@extractr-io/puphpeteer/src';

    parent::__construct(
        $base_dir.'/PuppeteerConnectionDelegate.js',
        new PuppeteerProcessDelegate,
        ['read_timeout' => 35],
            $userOptions
        );
}

This worked and I was able to generate a screenshot.

This isn't a permanent fix but I think it sheds some light on what is happening in my environment.

I'm not much of a node programmer, so I may have setup my node environment incorrectly or maybe this is a Windows OS issue? Also, I'm using coreybutler/nvm-windows to manage my node version. And I'm using Yarn to install puphpeteer.

Does this give you any insight into this issue?

Thanks.

from puphpeteer.

nesk avatar nesk commented on May 20, 2024

Thank you for your help @egifford, I'm starting to understand what's happening. NVM is probably what causes the issue. (@pavankumarkatakam, are you using NVM too?)

I will start working on a fix asap.

from puphpeteer.

knvpk avatar knvpk commented on May 20, 2024

Yes, I'm using the NVM. In this context, my NVM points to 8.9.3 NodeJs version.

from puphpeteer.

nesk avatar nesk commented on May 20, 2024

I've created a branch to support NVM in Rialto and PuPHPeteer, it would be great if both of you could clone this repository and run the following commands (use the same environment as before):

composer install
npm install
php run.php

The latest command should output OK, otherwise you will get an error, if its the case copy/paste it here.

from puphpeteer.

nesk avatar nesk commented on May 20, 2024

ooh! Actually, it could be much simpler! Could you tell me what's returned by npm list --depth=0 when you run this command in your original projects? (and not in my custom repository just above)

I've just found that PuPHPeteer doesn't work with Puppeteer v1.2+ with exactly the same error as you, so I want to check the version you're using.

from puphpeteer.

egifford avatar egifford commented on May 20, 2024

For the test project, I received OK as output.

For npm list --depth=0:

C:\Work\projects\BusinessSkills.D7\project\tools\testing
+-- @extractr-io/[email protected]
`-- [email protected]

from puphpeteer.

nesk avatar nesk commented on May 20, 2024

Thank you for your feedback. I will wait for @pavankumarkatakam to answer back befoe closing the issue.

I will also create a new release probably tomorrow to support Puppeteer v1.3 🙂

from puphpeteer.

knvpk avatar knvpk commented on May 20, 2024

For npm list --depth=0

For the test project, I received below output.

PHP Fatal error:  Uncaught Symfony\Component\Process\Exception\ProcessFailedException: The command "'node' '/home/administrator/Practise/puphpeteer-nvm-support/vendor/extractr-io/rialto/src/node-process/serve.js' '/home/administrator/Practise/puphpeteer-nvm-support/vendor/extractr-io/puphpeteer/src/PuppeteerConnectionDelegate.js' '{"idle_timeout":60}'" failed.

Exit Code: 1(General error)

Working directory: /home/administrator/Practise/puphpeteer-nvm-support

Output:
================


Error Output:
================
module.js:538
    throw err;
    ^

Error: Cannot find module 'puppeteer'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/administrator/Practise/puphpeteer-nvm-support/vendor/extractr-io/puphpeteer/src/PuppeteerConnectionDelegate.js:3:19)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at  in /home/administrator/Practise/puphpeteer-nvm-support/vendor/extractr-io/rialto/src/ProcessSupervisor.php on line 232

from puphpeteer.

7starsone avatar 7starsone commented on May 20, 2024

Hello, I get on php error log

PHP Fatal error: Uncaught Nesk\Rialto\Exceptions\Node\FatalException: Right-hand side of 'instanceof' is not callable in /home/myuser/public_html/tmp/pjs/vendor/nesk/rialto/src/ProcessSupervisor.php:230

from puphpeteer.

nesk avatar nesk commented on May 20, 2024

Paste here the logs emitted by PuPHPeteer, you can obtain them by using the logger option in the constructor.

from puphpeteer.

nesk avatar nesk commented on May 20, 2024

@7starsone If necessary, I've just created a guide to help you providing logs.

from puphpeteer.

7starsone avatar 7starsone commented on May 20, 2024
[2018-06-07 16:53:14] PuPHPeteer.WARNING: The installed version of Puppeteer (v1.1.1) doesn't match the requirements (~1.4.0), you may encounter issues. [] []
[2018-06-07 16:53:14] PuPHPeteer.DEBUG: [options] {"read_timeout":35,"logger":{}} [] []
[2018-06-07 16:53:14] PuPHPeteer.DEBUG: Starting process... [] []
[2018-06-07 16:53:14] PuPHPeteer.DEBUG: [PID 482] Process started [] []
[2018-06-07 16:53:14] PuPHPeteer.DEBUG: [PORT 33505] [sending] {"type":"call","name":"launch","catched":false,"value":[{"args":["--no-sandbox","--disable-setuid-sandbox"]}]} [] []
[2018-06-07 16:53:14] PuPHPeteer.DEBUG: [PORT 33505] [receiving]  [] []
[2018-06-07 16:53:14] PuPHPeteer.ERROR: [PID 482] [stderr] {"__rialto_error__":true,"message":"Right-hand side of 'instanceof' is not callable","stack":"TypeError: Right-hand side of 'instanceof' is not callable\n    at PuppeteerConnectionDelegate.handleInstruction (/home/myuser/public_html/tmp/pjs/vendor/nesk/puphpeteer/src/PuppeteerConnectionDelegate.js:42:19)\n    at <anonymous>\n    at process._tickCallback (internal/process/next_tick.js:182:7)"} [] []

so, is it about a Puppeteer update? I thought that

composer require nesk/puphpeteer
npm install @nesk/puphpeteer 

was enough to update Puppeteer. So, how to update it, instead?
Thanks

from puphpeteer.

nesk avatar nesk commented on May 20, 2024

Ah! I knew it! 😁

You have to run npm update @nesk/puphpeteer. If it doesn't work, try deleting the node_modules directory and run npm update.

from puphpeteer.

7starsone avatar 7starsone commented on May 20, 2024

that's fixed now but always an issue about the page content
eg. URL "edited" (not needed anymore)
the var_dump($page->content()); doesn't retrieve the container on the center, eg. the class _3rsz9QKOF3v-TD6wzRdTxc in this case.
What's the reason, please?
thanks

from puphpeteer.

nesk avatar nesk commented on May 20, 2024

Probably because you're trying to read the content before the JS has finished to retrieve the server data. Try to use the following method: page.waitFor(selectorOrFunctionOrTimeout[, options[, ...args]]).

If you have more questions about this, please head over to StackOverflow, because this doesn't seem to be related to a bug in PuPHPeteer or Puppeteer.

from puphpeteer.

7starsone avatar 7starsone commented on May 20, 2024

yes, the waitFor could be useful for a selector but if the content is dynamically loaded the real solution
in this case is something like

$response = $page->goto($url, [
    'waitUntil' => 'networkidle0', 
]);

it works, I didn't try other options there but for now is good as it is....
thank you very much

from puphpeteer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.