Skip to content

Support remote Playwright server - #307

Open
Propaganistas wants to merge 5 commits into
pestphp:5.xfrom
Propaganistas:support-remote-ws
Open

Propaganistas wants to merge 5 commits into
pestphp:5.xfrom
Propaganistas:support-remote-ws

Conversation

@Propaganistas

@Propaganistas Propaganistas commented Nov 7, 2026 •

Copy link
Copy Markdown

This PR enables the plugin to use remote Playwright servers instead of always spinning up a local one.

On a server / in a Docker container / ... :

npx -y playwright run-server ...

In Pest.php:

pest()->browser()->useWebsocket('ws://127.0.0.1:3000');

OR using CLI

./vendor/bin/pest --ci --ws ws://127.0.0.1:3000

My envisioned use case: leveraging the pre-built mcr.microsoft.com/playwright container and configure it as a service container in a GitHub workflow. This greatly reduces action minutes because browsers don't need to be downloaded in each run anymore; Github’s container cache is getting addressed instead. Below is a simplified example:

jobs:
  tests:
    runs-on: ubuntu-latest

    services:
      playwright:
        image: mcr.microsoft.com/playwright:v1.64.1-noble
        ports:
          - 3000:3000
        command: npx -y playwright run-server --port 3000 --host 0.0.0.0

    steps:
        # ...

        - name: Tests
          run: ./vendor/bin/pest --ci --ws ws://127.0.0.1:3000 --...
        

Disclaimer: this PR was fully coded by AI per explicit instructions. Code quality might be off, but it serves as a proof of concept. I've also deliberately chosen to avoid breaking changes in public methods. Happy to refine the code when interested.

@Propaganistas
Propaganistas marked this pull request as draft November 7, 2026 19:32
@Propaganistas

Copy link
Copy Markdown
Author

Putting in draft; it works for regular remote connections but not yet for containerized servers (the container can't reach the Laravel server yet)

@Propaganistas

Propaganistas commented Nov 7, 2026 •

Copy link
Copy Markdown
Author

Putting back to ready for review. Had to expose http server config as well to allow the service container be able to connect to the local Laravel http server.

The Playwright server version should match the installed version Pest will use. Here’s a run that consciously had a mismatch, causing the tests to fail with a clear error indicating that Pest uses the remote connection correctly:
https://github.com/Propaganistas/pest-remote-playwright-poc/actions/runs/42449798174/job/128636363708#step:9:68

I’ve also extended the workflow to 3 jobs covering all possibilities: a default job (Pest spins up Playwright), a job using an isolated Playwright server, and a job using a job-level service container: https://github.com/Propaganistas/pest-remote-playwright-poc/blob/master/.github/workflows/test.yml

https://github.com/Propaganistas/pest-remote-playwright-poc/actions/runs/42473688800

@Propaganistas
Propaganistas marked this pull request as ready for review November 7, 2026 21:11
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

Successfully merging this pull request may close these issues.

1 participant