@open-wxa/wxa-runner-core 0.12.0 → 0.12.1

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.
@@ -1769,6 +1769,7 @@ ${frames}` : "");
1769
1769
  function iframeWebViews(doc) {
1770
1770
  return Array.from(doc?.querySelectorAll("iframe[data-wxa-src]") ?? []).map((frame) => ({ src: frame.dataset.wxaSrc, windowName: null }));
1771
1771
  }
1772
+ var COMMIT_WAIT_MS = 5e3;
1772
1773
  var WebViewWindows = class {
1773
1774
  /** @param isShown 页面当前是否显示:隐藏的页面先记下地址,显示时再打开窗口 */
1774
1775
  constructor(device, isShown) {
@@ -1847,14 +1848,36 @@ ${frames}` : "");
1847
1848
  open(record) {
1848
1849
  if (!record.src) return;
1849
1850
  if (record.win && !record.win.closed) {
1850
- record.win.location.href = record.src;
1851
+ this.navigate(record);
1851
1852
  } else {
1852
1853
  const features = `popup,width=${this.device.screenWidth},height=${this.device.screenHeight}`;
1853
1854
  record.win = window.open(record.src, record.name, features);
1854
- if (record.win) notify("open", record.name, record.src);
1855
+ if (record.win) {
1856
+ record.opening = { src: record.src, at: Date.now() };
1857
+ notify("open", record.name, record.src);
1858
+ }
1855
1859
  }
1856
1860
  this.render(record);
1857
1861
  }
1862
+ /**
1863
+ * 已打开的窗口跳到最新的 src。用已有的引用跳转,不靠窗口名:网页可能改了自己的 window.name,按名字找不到时会多开一个窗口。
1864
+ *
1865
+ * Chrome 里新窗口的初始页面还没提交时改它的地址,这次跳转偶尔会被丢掉,窗口停在原来的网页上(不经过 CDP 也一样)。
1866
+ * 窗口刚打开就改 src 会碰上,所以等初始页面提交后再跳
1867
+ */
1868
+ navigate(record) {
1869
+ const win = record.win;
1870
+ if (!win || win.closed || !record.src || record.retry !== void 0) return;
1871
+ if (record.opening && !committed(win, record.opening.src) && Date.now() - record.opening.at < COMMIT_WAIT_MS) {
1872
+ record.retry = window.setTimeout(() => {
1873
+ record.retry = void 0;
1874
+ this.navigate(record);
1875
+ }, 20);
1876
+ return;
1877
+ }
1878
+ record.opening = void 0;
1879
+ win.location.href = record.src;
1880
+ }
1858
1881
  render(record) {
1859
1882
  const opened = record.win && !record.win.closed;
1860
1883
  const [title, detail] = !record.src ? ["web-view \u8FD8\u6CA1\u6709\u8BBE\u7F6E src", ""] : opened ? ["H5 \u5DF2\u5728\u65B0\u7A97\u53E3\u6253\u5F00", record.src] : record.win === null && this.isShown(record.webviewId) ? ["\u6D4F\u89C8\u5668\u62E6\u622A\u4E86\u5F39\u51FA\u7A97\u53E3\uFF0C\u70B9\u4E0B\u9762\u7684\u6309\u94AE\u6253\u5F00 H5", record.src] : ["H5 \u5728\u65B0\u7A97\u53E3\u6253\u5F00", record.src];
@@ -1869,7 +1892,17 @@ ${frames}` : "");
1869
1892
  function windowName(webviewId, htmlId) {
1870
1893
  return `wxa-h5-${webviewId}-${htmlId}`;
1871
1894
  }
1895
+ function committed(win, src) {
1896
+ try {
1897
+ return win.location.href !== "about:blank" || src === "about:blank";
1898
+ } catch {
1899
+ return true;
1900
+ }
1901
+ }
1872
1902
  function close(record) {
1903
+ clearTimeout(record.retry);
1904
+ record.retry = void 0;
1905
+ record.opening = void 0;
1873
1906
  if (!record.win) return;
1874
1907
  record.win.close();
1875
1908
  record.win = null;