'script_not_found', 'path' => $script]); exit; } // Set env for playwright modules putenv('NODE_PATH=/usr/lib/node_modules'); // Long timeout for Playwright video (up to 2 min) $output = shell_exec('cd /usr/lib/node_modules && timeout 120 bash ' . escapeshellarg($script) . ' 2>&1 | tail -c 500'); if (trim((string)$output) === '') { http_response_code(500); echo json_encode(['error' => 'empty_output']); exit; } // Try extract last JSON line $lines = array_filter(array_map('trim', explode("\n", $output))); $last = end($lines); $parsed = @json_decode($last, true); if ($parsed && isset($parsed['proof_url'])) { echo json_encode([ 'ok' => true, 'proof_url' => $parsed['proof_url'], 'ts' => $parsed['ts'], 'raw' => $output ]); } else { echo $output; }