@guanzhu.me/pw-cli 0.0.4 → 0.0.5
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.
- package/bin/pw-cli.js +5 -21
- package/package.json +1 -1
package/bin/pw-cli.js
CHANGED
|
@@ -760,31 +760,15 @@ 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
|
|
764
|
-
//
|
|
765
|
-
//
|
|
766
|
-
// (lenient wait strategy so redirects/login flows/SPA routing never time out)
|
|
763
|
+
// If a URL is provided with open, always use our CDP executor directly.
|
|
764
|
+
// getConnection() handles all cases: reuse playwright-cli session, reuse own daemon,
|
|
765
|
+
// or start a new daemon — so we never need to spawn playwright-cli open separately.
|
|
767
766
|
const rawUrlArg = afterOpen.find(a => !a.startsWith('-') && /^(https?:\/\/|[a-zA-Z0-9]([a-zA-Z0-9-]*\.)+[a-zA-Z]{2,})/.test(a));
|
|
768
767
|
const urlArg = rawUrlArg && !/^https?:\/\//.test(rawUrlArg) ? `https://${rawUrlArg}` : rawUrlArg;
|
|
769
768
|
if (urlArg) {
|
|
770
769
|
const navCode = `async page => { const newPage = await page.context().newPage(); await newPage.goto(${JSON.stringify(urlArg)}, { waitUntil: 'domcontentloaded', timeout: 0 }); return newPage.url(); }`;
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
// Browser already running — create a new tab directly, skip playwright-cli open
|
|
774
|
-
await handleRunCode(['run-code', navCode]);
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
777
|
-
const { spawnSync } = require('child_process');
|
|
778
|
-
const openOnlyArgs = injectOpenDefaults(afterOpen.filter(a => a !== rawUrlArg));
|
|
779
|
-
const res = spawnSync(process.execPath, [cliPath, 'open', ...openOnlyArgs], {
|
|
780
|
-
stdio: 'inherit',
|
|
781
|
-
cwd: PW_CLI_DIR,
|
|
782
|
-
});
|
|
783
|
-
if (res.status !== 0) {
|
|
784
|
-
process.stderr.write('pw-cli: failed to open browser\n');
|
|
785
|
-
process.exit(res.status || 1);
|
|
786
|
-
}
|
|
787
|
-
argv = ['run-code', navCode];
|
|
770
|
+
await handleRunCode(['run-code', navCode]);
|
|
771
|
+
return;
|
|
788
772
|
} else {
|
|
789
773
|
const enhanced = injectOpenDefaults(afterOpen);
|
|
790
774
|
argv = [...argv.slice(0, openIdx + 1), ...enhanced];
|
package/package.json
CHANGED