teodesian/playwright-perl

Startup issues

Closed this issue · 12 comments

  1. $server_bin is set incorrectly for me (I had to fix this a few versions ago and thought the issue was gone). pwp_server_bin_patch.txt
  2. With the above patch applied, it fails saying:
Waiting for port to come up...
Required dependencies are not installed. Cannot continue, run `npm i` to fix.

The only difference from my previously working installation was upgrading to Playwright-0.010 via cpanm Playwright.

Interesting. So which can't find playwright_server, and you had to patch it because the location it is installed differs with another degree of depth from where it lives in the repo. I should probably search that as well.

I had other clients have issues with startup finding node dependencies and had to make some tweaks.
If you have NODE_PATH set, it will now honor that for looking for the various dependencies.

Suggestion:

run playwright_server directly.

Patch out the try/catch around the require() statements, and it should tell you what's actually failing.
I'll try and reproduce on my end.

Seems they changed up the way they install deps on the latest version too:

NODE_PATH=/usr/local/bin/node_modules perl example.pl 
Waiting for port to come up...
done
  pw:api => browserType.launch started +0ms
  pw:api <= browserType.launch failed +126ms
browserType.launch: 
╔════════════════════════════════════════════════════════════╗
║ Host system is missing a few dependencies to run browsers. ║
║ Please install them with the following command:            ║
║                                                            ║
║     sudo npx playwright install-deps                       ║
║                                                            ║
║ <3 Playwright Team                                         ║
╚════════════════════════════════════════════════════════════╝ at /usr/local/share/perl/5.30.0/Playwright/Util.pm line 31.
	Playwright::Util::request("POST", "session", 45163, LWP::UserAgent=HASH(0x55d4a7b46c98), "type", "firefox", "args", ARRAY(0x55d4a85e8848)) called at /usr/local/share/perl/5.30.0/Playwright.pm line 233
	Playwright::launch(Playwright=HASH(0x55d4a6e7f068), "headless", 0, "type", "firefox") called at example.pl line 13
Attempting to terminate server process...

NODE_PATH can have multiple dirs, and apparently the separator differs across OSes:
https://stackoverflow.com/questions/45893524/how-to-add-multiple-node-path-in-package-json

That makes sense why that would fail then. I'll have to do extended parses/tries then.

It works when I change the if statement to fall through to the else:

//    if (process.env.NODE_PATH) {                                                                                                                                                                          
    if (0) {

I have NODE_PATH set and it works without any special logic. Not sure why the if clause needed.

It didn't appear to be honored without making the pathing explicit on my test system. YMMV?

Ok, looking into how node deps are installed, and how whacked global modules are in general I'm just going to hard splash-down if we don't have stuff and make 0 attempts whatsoever to auto-install anything for the user or suppress the output of playwright_server's startup process in any way. If the deps can't be figured out, that's gonna be the user's problem, not mine.

also tempted to remove necessity for the patch in the OC by forcing people to setup their PATH correctly. I think I'll do that too, and provide extended error messaging. What i'm going with for the node deps:

playwright_server could not run successfully.
    See the above error message for why.
    It's likely to be unmet dependencies, or a NODE_PATH issue.

    Install of node dependencies must be done manually.
    Run the following:

    npm i express playwright uuid
    sudo npx playwright install-deps
    export NODE_PATH="$(cwd)/node_modules:$NODE_PATH".
     at lib/Playwright.pm line 228.
BEGIN failed--compilation aborted at lib/Playwright.pm line 345.
Compilation failed in require at example.pl line 6.
BEGIN failed--compilation aborted at example.pl line 6.

Observation of behavior of NODE_PATH using colon delimiters:

doge@doge-perldev:~$ NODE_DEBUG=module NODE_PATH="$(pwd)/node/node_modules:$NODE_PATH" playwright_server --check
MODULE 5502: looking for "/usr/local/bin/playwright_server" in ["/home/doge/node/node_modules","/home/doge/.node_modules","/home/doge/.node_libraries","/usr/lib/x86_64-linux-gnu/nodejs","/usr/share/nodejs","/usr/lib/nodejs"]
MODULE 5502: load "/usr/local/bin/playwright_server" for module "."
MODULE 5502: Module._load REQUEST process parent: .
MODULE 5502: load native module process
MODULE 5502: Module._load REQUEST fs parent: .
MODULE 5502: load native module fs
MODULE 5502: Module._load REQUEST path parent: .
MODULE 5502: load native module path
MODULE 5502: Module._load REQUEST /home/doge/node/node_modules:/uuid parent: .
MODULE 5502: looking for "/home/doge/node/node_modules:/uuid" in ["/usr/local/bin/node_modules","/usr/local/node_modules","/usr/node_modules","/node_modules","/home/doge/node/node_modules","/home/doge/.node_modules","/home/doge/.node_libraries","/usr/lib/x86_64-linux-gnu/nodejs","/usr/share/nodejs","/usr/lib/nodejs"]
Required dependencies are not installed. Cannot continue, run `npm i` to fix.

It absolutely fails to do the right thing and remove the trailing colon, leading me to conclude this is in fact not correct usage.
Removing the list from NODE_PATH fixes it.

Ultimately it appears NODE_PATH is little more than a shim to assist with execution of specific scripts.

That said, this approach should work.

uploaded new version to CPAN.