playwright-community / playwright-go

Playwright for Go a browser automation library to control Chromium, Firefox and WebKit with a single API.
https://playwright-community.github.io/playwright-go/
MIT License
2.26k stars 163 forks source link

[Feature]: Allow us to set the full path to cli js (driver) #496

Closed hmajid2301 closed 2 weeks ago

hmajid2301 commented 1 month ago

Does the upstream have similar features?

I don't know, this is a code-specific feature request. Please let me know if I should request is there.

Is your feature request related to a problem? Please describe.

This is probably a very niche use case of this library. I am using Nix to set up my development environment (and also NixOS). I have set up playwright using this flake, https://github.com/pietdevries94/playwright-web-flake.

The cli.js is then made available at this path: /nix/store/l15bkcb7w90zm1h08qbdq9fc0ssf7sg4-_at_playwright_slash_test-1.47.2/lib/node_modules/@playwright/test/node_modules/playwright-core/cli.js (for example)

As you can see, with the current code in run.go and the getDriverCliJs function, it expects it to be within the package.

Describe the solution you'd like

Would it be possible to maybe set an environment variable or an option to allow us to hardcode this?

Default to this, or allow us to set the path in the constructor? I guess this would make the code a bit more complex. But just a thought.

filepath.Join(driverDirectory, "package", "cli.js")

Additional context

Nix the package manager expects things to be installed differently to a lot of other package managers, so hence this is an issue for me using it.

Thanks in advance

hmajid2301 commented 2 weeks ago

Anyone who is using playwright-web-flake, https://github.com/pietdevries94/playwright-web-flake

You can do something like so now: PLAYWRIGHT_DRIVER_PATH="${pkgs.playwright-driver}". In my nix flake dev shell: https://gitlab.com/hmajid2301/banterbus/-/blob/a13215011408af7885feb361176ff6db868ef774/shell.nix#L43-46

Thanks @canstand!!!

canstand commented 2 weeks ago

Happy to help. The PR #501 is aligned with similar behavior of clients like playright-python/dotnet/java. If it doesn't work well, I tend to create symbolic links or other generic ways.