@guanzhu.me/pw-cli 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/pw-cli.js +11 -6
  2. package/package.json +1 -1
package/bin/pw-cli.js CHANGED
@@ -760,12 +760,19 @@ async function main() {
760
760
  const openIdx = argv.indexOf('open');
761
761
  const afterOpen = argv.slice(openIdx + 1);
762
762
 
763
- // If a URL is provided with open, split into two steps to avoid goto timeout:
764
- // 1) spawn open (no URL) to start the browser daemon
765
- // 2) navigate via run-code with waitUntil:'domcontentloaded' + timeout:0
766
- // so redirects (login flows, SPA routing) never time out
763
+ // If a URL is provided with open:
764
+ // - If a session is already running: open a new tab directly via our CDP executor
765
+ // - Otherwise: spawn open (no URL) to start the browser, then navigate via playwright-cli run-code
766
+ // (lenient wait strategy so redirects/login flows/SPA routing never time out)
767
767
  const urlArg = afterOpen.find(a => !a.startsWith('-') && /^https?:\/\//.test(a));
768
768
  if (urlArg) {
769
+ const navCode = `async page => { const newPage = await page.context().newPage(); await newPage.goto(${JSON.stringify(urlArg)}, { waitUntil: 'domcontentloaded', timeout: 0 }); return newPage.url(); }`;
770
+ const alive = await isSessionAlive(session);
771
+ if (alive) {
772
+ // Browser already running — create a new tab directly, skip playwright-cli open
773
+ await handleRunCode(['run-code', navCode]);
774
+ return;
775
+ }
769
776
  const { spawnSync } = require('child_process');
770
777
  const openOnlyArgs = injectOpenDefaults(afterOpen.filter(a => a !== urlArg));
771
778
  const res = spawnSync(process.execPath, [cliPath, 'open', ...openOnlyArgs], {
@@ -776,8 +783,6 @@ async function main() {
776
783
  process.stderr.write('pw-cli: failed to open browser\n');
777
784
  process.exit(res.status || 1);
778
785
  }
779
- // Replace open+url with a run-code navigation (lenient wait strategy)
780
- const navCode = `async page => { const newPage = await page.context().newPage(); await newPage.goto(${JSON.stringify(urlArg)}, { waitUntil: 'domcontentloaded', timeout: 0 }); return newPage.url(); }`;
781
786
  argv = ['run-code', navCode];
782
787
  } else {
783
788
  const enhanced = injectOpenDefaults(afterOpen);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guanzhu.me/pw-cli",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Persistent Playwright browser CLI with headed defaults, profile support, queueing, and script execution",
5
5
  "bin": {
6
6
  "pw-cli": "./bin/pw-cli.js"