@stacksjs/stx 0.2.96 → 0.2.98

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.
@@ -7,17 +7,31 @@ function toUrl(input) {
7
7
  return input;
8
8
  return `file://${path.resolve(input)}`;
9
9
  }
10
- function waitForNavigation(view, waitMs, timeoutMs) {
10
+ function navigateAndWait(view, url, waitMs, timeoutMs) {
11
11
  return new Promise((resolve) => {
12
- let settled = !1;
12
+ let settled = !1, settleTimer, timeoutTimer;
13
13
  const finish = () => {
14
14
  if (!settled) {
15
15
  settled = !0;
16
+ clearTimeout(timeoutTimer);
17
+ if (settleTimer)
18
+ clearTimeout(settleTimer);
19
+ view.onNavigated = void 0;
16
20
  resolve();
17
21
  }
18
22
  };
19
- view.onNavigated = () => setTimeout(finish, waitMs);
20
- setTimeout(finish, timeoutMs);
23
+ timeoutTimer = setTimeout(finish, timeoutMs);
24
+ view.onNavigated = () => {
25
+ if (!settled)
26
+ settleTimer = setTimeout(finish, waitMs);
27
+ };
28
+ try {
29
+ const navigation = view.navigate(url);
30
+ if (navigation && typeof navigation.catch === "function")
31
+ navigation.catch(finish);
32
+ } catch {
33
+ finish();
34
+ }
21
35
  });
22
36
  }
23
37
  async function waitForSelector(view, selector, timeoutMs) {
@@ -40,7 +54,6 @@ async function measureFullHeight(view) {
40
54
  }
41
55
  export async function captureScreenshot(input, output, opts = {}) {
42
56
  const width = Math.min(opts.width ?? 1440, MAX_DIMENSION), height = Math.min(opts.height ?? 2200, MAX_DIMENSION), waitMs = opts.waitMs ?? 800, timeoutMs = opts.timeoutMs ?? 15000, format = opts.format ?? "png", url = toUrl(input), open = (h) => new WebView({
43
- url,
44
57
  width,
45
58
  height: h,
46
59
  headless: !0,
@@ -48,7 +61,7 @@ export async function captureScreenshot(input, output, opts = {}) {
48
61
  });
49
62
  let view = open(height);
50
63
  try {
51
- await waitForNavigation(view, waitMs, timeoutMs);
64
+ await navigateAndWait(view, url, waitMs, timeoutMs);
52
65
  if (opts.waitSelector)
53
66
  await waitForSelector(view, opts.waitSelector, timeoutMs);
54
67
  if (opts.fullPage) {
@@ -56,7 +69,7 @@ export async function captureScreenshot(input, output, opts = {}) {
56
69
  if (full > height) {
57
70
  view.close();
58
71
  view = open(full);
59
- await waitForNavigation(view, waitMs, timeoutMs);
72
+ await navigateAndWait(view, url, waitMs, timeoutMs);
60
73
  if (opts.waitSelector)
61
74
  await waitForSelector(view, opts.waitSelector, timeoutMs);
62
75
  }