@guanzhu.me/pw-cli 0.0.4 → 0.0.6
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 +26 -21
- package/package.json +1 -1
package/bin/pw-cli.js
CHANGED
|
@@ -716,6 +716,27 @@ async function main() {
|
|
|
716
716
|
return;
|
|
717
717
|
}
|
|
718
718
|
|
|
719
|
+
// ── goto: navigate the currently active tab (not always the first one) ───
|
|
720
|
+
if (command === 'goto') {
|
|
721
|
+
const gotoIdx = rawArgv.indexOf('goto');
|
|
722
|
+
const afterGoto = rawArgv.slice(gotoIdx + 1);
|
|
723
|
+
const rawUrl = afterGoto.find(a => !a.startsWith('-'));
|
|
724
|
+
if (rawUrl) {
|
|
725
|
+
const fullUrl = /^https?:\/\//.test(rawUrl) ? rawUrl : `https://${rawUrl}`;
|
|
726
|
+
const navCode = `async (page, context) => {
|
|
727
|
+
const pages = context.pages();
|
|
728
|
+
let target = pages[pages.length - 1] || page;
|
|
729
|
+
for (const p of pages) {
|
|
730
|
+
try { if (!await p.evaluate(() => document.hidden)) { target = p; break; } } catch {}
|
|
731
|
+
}
|
|
732
|
+
await target.goto(${JSON.stringify(fullUrl)}, { waitUntil: 'domcontentloaded', timeout: 0 });
|
|
733
|
+
return target.url();
|
|
734
|
+
}`;
|
|
735
|
+
await handleRunCode(['run-code', navCode]);
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
719
740
|
// ── From here on: delegate to playwright-cli (with enhancements) ─────────
|
|
720
741
|
const cliPath = findPlaywrightCli();
|
|
721
742
|
if (!cliPath) {
|
|
@@ -760,31 +781,15 @@ async function main() {
|
|
|
760
781
|
const openIdx = argv.indexOf('open');
|
|
761
782
|
const afterOpen = argv.slice(openIdx + 1);
|
|
762
783
|
|
|
763
|
-
// If a URL is provided with open
|
|
764
|
-
//
|
|
765
|
-
//
|
|
766
|
-
// (lenient wait strategy so redirects/login flows/SPA routing never time out)
|
|
784
|
+
// If a URL is provided with open, always use our CDP executor directly.
|
|
785
|
+
// getConnection() handles all cases: reuse playwright-cli session, reuse own daemon,
|
|
786
|
+
// or start a new daemon — so we never need to spawn playwright-cli open separately.
|
|
767
787
|
const rawUrlArg = afterOpen.find(a => !a.startsWith('-') && /^(https?:\/\/|[a-zA-Z0-9]([a-zA-Z0-9-]*\.)+[a-zA-Z]{2,})/.test(a));
|
|
768
788
|
const urlArg = rawUrlArg && !/^https?:\/\//.test(rawUrlArg) ? `https://${rawUrlArg}` : rawUrlArg;
|
|
769
789
|
if (urlArg) {
|
|
770
790
|
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];
|
|
791
|
+
await handleRunCode(['run-code', navCode]);
|
|
792
|
+
return;
|
|
788
793
|
} else {
|
|
789
794
|
const enhanced = injectOpenDefaults(afterOpen);
|
|
790
795
|
argv = [...argv.slice(0, openIdx + 1), ...enhanced];
|
package/package.json
CHANGED