@guanzhu.me/pw-cli 0.0.3 → 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 +7 -22
- package/package.json +1 -1
package/bin/pw-cli.js
CHANGED
|
@@ -760,30 +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
|
-
|
|
767
|
-
const urlArg =
|
|
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.
|
|
766
|
+
const rawUrlArg = afterOpen.find(a => !a.startsWith('-') && /^(https?:\/\/|[a-zA-Z0-9]([a-zA-Z0-9-]*\.)+[a-zA-Z]{2,})/.test(a));
|
|
767
|
+
const urlArg = rawUrlArg && !/^https?:\/\//.test(rawUrlArg) ? `https://${rawUrlArg}` : rawUrlArg;
|
|
768
768
|
if (urlArg) {
|
|
769
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
|
-
|
|
771
|
-
|
|
772
|
-
// Browser already running — create a new tab directly, skip playwright-cli open
|
|
773
|
-
await handleRunCode(['run-code', navCode]);
|
|
774
|
-
return;
|
|
775
|
-
}
|
|
776
|
-
const { spawnSync } = require('child_process');
|
|
777
|
-
const openOnlyArgs = injectOpenDefaults(afterOpen.filter(a => a !== urlArg));
|
|
778
|
-
const res = spawnSync(process.execPath, [cliPath, 'open', ...openOnlyArgs], {
|
|
779
|
-
stdio: 'inherit',
|
|
780
|
-
cwd: PW_CLI_DIR,
|
|
781
|
-
});
|
|
782
|
-
if (res.status !== 0) {
|
|
783
|
-
process.stderr.write('pw-cli: failed to open browser\n');
|
|
784
|
-
process.exit(res.status || 1);
|
|
785
|
-
}
|
|
786
|
-
argv = ['run-code', navCode];
|
|
770
|
+
await handleRunCode(['run-code', navCode]);
|
|
771
|
+
return;
|
|
787
772
|
} else {
|
|
788
773
|
const enhanced = injectOpenDefaults(afterOpen);
|
|
789
774
|
argv = [...argv.slice(0, openIdx + 1), ...enhanced];
|
package/package.json
CHANGED