Browser plugin: keep the Playwright server's output when it crashes
Maintainers usually reply within 5 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start by reading src/Playwright/Servers/PlaywrightNpmServer.php in pestphp/pest-plugin-browser, especially how the server process starts and how it detects the listening line. Check the existing tests for PlaywrightNpmServer and add coverage for logging to the configured file and startup detection; done means the log captures output when PEST_BROWSER_SERVER_LOG is set while the unset behavior remains unchanged.
Written by the indexing model from the issue text.
Description
Problem
PlaywrightNpmServer reads the Playwright server's output through a pipe held by the test process. When the server crashes mid-suite, whatever it printed last is lost with the pipe: the suite reports hundreds of Client unexpectedly closed failures and nothing says why the server went down.
Proposal
An opt-in environment variable, PEST_BROWSER_SERVER_LOG. When it names a file, the server command appends its stdout and stderr to that file as it comes, and startup detection reads the "listening" line from the file instead of the pipe. When the variable is unset, nothing changes.
Why a file
A file survives the process that wrote it. After a crash the last lines are still there, and a CI job can keep them as an artifact.
Patch
About 35 lines in src/Playwright/Servers/PlaywrightNpmServer.php of pestphp/pest-plugin-browser (written against 5.0.1). We have been running it since early November on a large browser suite across 6 parallel processes. Happy to open a pull request against 5.x if the approach suits you.
Diff
diff --git a/src/Playwright/Servers/PlaywrightNpmServer.php b/src/Playwright/Servers/PlaywrightNpmServer.php
--- a/src/Playwright/Servers/PlaywrightNpmServer.php
+++ b/src/Playwright/Servers/PlaywrightNpmServer.php
@@ -24,6 +24,11 @@
private const string PLAYWRIGHT_VERSION = '1.62.1';
/**
+ * The environment variable naming the file the server's output is appended to.
+ */
+ public const string LOG = 'PEST_BROWSER_SERVER_LOG';
+
+ /**
* The underlying process instance, if any.
*/
private ?SystemProcess $systemProcess = null;
@@ -60,11 +65,27 @@
return;
}
- $this->systemProcess = SystemProcess::fromShellCommandline(sprintf(
+ $command = sprintf(
$this->command,
$this->host,
$this->port,
- ), $this->baseDirectory, [
+ );
+
+ // The file the server's output is appended to as it comes, when one is
+ // named: the output a pipe holds is lost with the process that reads it,
+ // and a server that crashes writes nothing once it is gone.
+ $log = getenv(self::LOG);
+ $log = is_string($log) && $log !== '' ? $log : null;
+ $offset = 0;
+
+ if ($log !== null) {
+ $command .= ' >> '.escapeshellarg($log).' 2>&1';
+
+ clearstatcache(true, $log);
+ $offset = is_file($log) ? (int) filesize($log) : 0;
+ }
+
+ $this->systemProcess = SystemProcess::fromShellCommandline($command, $this->baseDirectory, [
'APP_URL' => sprintf('http://%s:%d', $this->host, $this->port),
]);
@@ -72,10 +93,22 @@
$this->systemProcess->start();
- $this->systemProcess->waitUntil(
- fn (string $type, string $output): bool => str_contains($output, $this->until)
- );
+ if ($log === null) {
+ $this->systemProcess->waitUntil(
+ fn (string $type, string $output): bool => str_contains($output, $this->until)
+ );
+ } else {
+ while ($this->isRunning()) {
+ $written = @file_get_contents($log, false, null, $offset);
+ if (is_string($written) && str_contains($written, $this->until)) {
+ break;
+ }
+
+ usleep(10_000);
+ }
+ }
+
if ($this->isRunning() === false) {
self::ensurePlaywrightIsInstalledAndVersionIsSupported();
- Dominant language
- PHP
- Stars
- 11.8k
- Forks
- 559
- Avg merge
- 5d 23h
- Merged PRs (30d)
- 24
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pestphp/pest
-
[Bug]: --mutate hides unreadable files, so mutants behind a failed read can never be killedMay be free again A pull request for this issue was closed without being merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 5 days
-
[Bug]: [mutate] Windows: @pest-mutate-ignore comments land on line 1 in files with LF line endingsPossibly taken @webdevsamran claimed this 57 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 5 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Maintainers usually reply within 5 days
-
[pest-plugin-browser] Page::waitForLoadState() never sends its message — waitForEvent() is a silent no-opPossibly taken @asllanmaciel claimed this 70 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
pestphp/pest#1892 · 2 comments ·
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 5 days
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
mailcow/mailcow-dockerized#7668 · 5 comments · 2 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
lara-zeus/spatie-translatable#80 ·
Maintainers usually reply within 1 day
-
small
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
uiowa/uiowa#10296 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
asyncapi/modelina#2709 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
My-Little-Forum/mylittleforum#937 ·