@guanzhu.me/pw-cli 0.0.5 → 0.0.7
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 +29 -0
- package/package.json +1 -1
package/bin/pw-cli.js
CHANGED
|
@@ -716,6 +716,35 @@ 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
|
+
const info = await Promise.all(pages.map(async p => {
|
|
729
|
+
try {
|
|
730
|
+
const [hidden, focused] = await Promise.all([
|
|
731
|
+
p.evaluate(() => document.hidden),
|
|
732
|
+
p.evaluate(() => document.hasFocus()),
|
|
733
|
+
]);
|
|
734
|
+
return { p, hidden, focused };
|
|
735
|
+
} catch { return { p, hidden: true, focused: false }; }
|
|
736
|
+
}));
|
|
737
|
+
const focused = info.find(v => v.focused);
|
|
738
|
+
const visible = info.filter(v => !v.hidden);
|
|
739
|
+
const target = (focused || visible[visible.length - 1] || info[info.length - 1]).p;
|
|
740
|
+
await target.goto(${JSON.stringify(fullUrl)}, { waitUntil: 'domcontentloaded', timeout: 0 });
|
|
741
|
+
return target.url();
|
|
742
|
+
}`;
|
|
743
|
+
await handleRunCode(['run-code', navCode]);
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
719
748
|
// ── From here on: delegate to playwright-cli (with enhancements) ─────────
|
|
720
749
|
const cliPath = findPlaywrightCli();
|
|
721
750
|
if (!cliPath) {
|
package/package.json
CHANGED