@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.
Files changed (2) hide show
  1. package/bin/pw-cli.js +12 -4
  2. 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
- 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
- }
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guanzhu.me/pw-cli",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Persistent Playwright browser CLI with headed defaults, profile support, queueing, and script execution",
5
5
  "bin": {
6
6
  "pw-cli": "./bin/pw-cli.js"