@guanzhu.me/pw-cli 0.0.6 → 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 +12 -4
- package/package.json +1 -1
package/bin/pw-cli.js
CHANGED
|
@@ -725,10 +725,18 @@ async function main() {
|
|
|
725
725
|
const fullUrl = /^https?:\/\//.test(rawUrl) ? rawUrl : `https://${rawUrl}`;
|
|
726
726
|
const navCode = `async (page, context) => {
|
|
727
727
|
const pages = context.pages();
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
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;
|
|
732
740
|
await target.goto(${JSON.stringify(fullUrl)}, { waitUntil: 'domcontentloaded', timeout: 0 });
|
|
733
741
|
return target.url();
|
|
734
742
|
}`;
|
package/package.json
CHANGED