@enhance-eng/sdk 0.1.161 → 0.1.166
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/README.md +5 -2
- package/dist/browser/kernel.iife.js +1785 -391
- package/dist/{capture-client.client-BM_NxOqy.mjs → capture-client.client-GeV8SAsY.mjs} +3 -3
- package/dist/{capture-context.lib-LXUORfkL.mjs → capture-context.lib-DQn7JA02.mjs} +2 -2
- package/dist/client.mjs +1 -1
- package/dist/environment.config-uvF4VFma.mjs +83 -0
- package/dist/index.mjs +2 -2
- package/dist/{package-BFIjCgBc.mjs → package-362fShMl.mjs} +1 -1
- package/dist/playwright/index.mjs +175 -70
- package/dist/playwright/reporter.mjs +4 -4
- package/dist/{stall-watch.lib-DgIzqC3b.mjs → stall-watch.lib-DL_Gnxep.mjs} +534 -68
- package/package.json +2 -2
- package/dist/environment.config-BlBA4N5X.mjs +0 -34
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { A as captureSelection, C as isCaptureError, E as updateCaptureReferenceInputSchema, H as captureRunDescriptorSchema, L as beginCaptureRunInputSchema, R as beginCaptureRunOutputSchema, S as captureError, T as captureReviewSchema, U as getCaptureRunOutputSchema, W as reserveCaptureBlobsOutputSchema, _ as writeCapturePayload, a as requestOutcomeOf, d as captureDiagnostics, g as writeCaptureJson, h as writeCaptureBlob, j as mergeCaptureManifests, k as captureBlobs, m as verifiedCaptureBlobPath, n as retrying, o as retryAfterMsOf, p as readCaptureManifest, t as startStallWatch, w as captureReferenceSchema, x as captureManifestDigest } from "./stall-watch.lib-
|
|
1
|
+
import { A as captureSelection, C as isCaptureError, E as updateCaptureReferenceInputSchema, H as captureRunDescriptorSchema, L as beginCaptureRunInputSchema, R as beginCaptureRunOutputSchema, S as captureError, T as captureReviewSchema, U as getCaptureRunOutputSchema, W as reserveCaptureBlobsOutputSchema, _ as writeCapturePayload, a as requestOutcomeOf, d as captureDiagnostics, g as writeCaptureJson, h as writeCaptureBlob, j as mergeCaptureManifests, k as captureBlobs, m as verifiedCaptureBlobPath, n as retrying, o as retryAfterMsOf, p as readCaptureManifest, t as startStallWatch, w as captureReferenceSchema, x as captureManifestDigest } from "./stall-watch.lib-DL_Gnxep.mjs";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { openAsBlob } from "node:fs";
|
|
4
|
+
import nodePath from "node:path";
|
|
3
5
|
import process from "node:process";
|
|
4
6
|
import { mkdir } from "node:fs/promises";
|
|
5
|
-
import nodePath from "node:path";
|
|
6
|
-
import { openAsBlob } from "node:fs";
|
|
7
7
|
//#region src/node/capture-output.lib.ts
|
|
8
8
|
const line = (text) => `Enhance: ${text}\n`;
|
|
9
9
|
/** A left-out capture by its journey and step, or by its test when it could not be read at all. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { H as captureRunDescriptorSchema, S as captureError } from "./stall-watch.lib-
|
|
1
|
+
import { H as captureRunDescriptorSchema, S as captureError } from "./stall-watch.lib-DL_Gnxep.mjs";
|
|
2
|
+
import nodePath from "node:path";
|
|
2
3
|
import process from "node:process";
|
|
3
4
|
import { readFile } from "node:fs/promises";
|
|
4
|
-
import nodePath from "node:path";
|
|
5
5
|
//#region src/playwright/environment.config.ts
|
|
6
6
|
const captureEnvironment = () => ({ directory: process.env["ENHANCE_CAPTURE_DIRECTORY"] ?? "" });
|
|
7
7
|
const setCaptureDirectory = (directory) => {
|
package/dist/client.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createEnhance } from "./capture-client.client-
|
|
1
|
+
import { t as createEnhance } from "./capture-client.client-GeV8SAsY.mjs";
|
|
2
2
|
export { createEnhance };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { S as captureError } from "./stall-watch.lib-DL_Gnxep.mjs";
|
|
2
|
+
import { t as version } from "./package-362fShMl.mjs";
|
|
3
|
+
import { t as createEnhance$1 } from "./capture-client.client-GeV8SAsY.mjs";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import nodePath from "node:path";
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
//#region src/node/environment.config.ts
|
|
9
|
+
const endpoints = {
|
|
10
|
+
local: "http://localhost:3000",
|
|
11
|
+
development: "https://api.enhance3.karunalabs.ai",
|
|
12
|
+
production: "https://api.enhancelabs.ai"
|
|
13
|
+
};
|
|
14
|
+
/** Where each released CLI keeps its sign-in, and the command that makes it. */
|
|
15
|
+
const cliSignIns = {
|
|
16
|
+
development: {
|
|
17
|
+
directory: "enhance-development",
|
|
18
|
+
macDirectory: "Enhance Development",
|
|
19
|
+
command: "enhance-dev auth login"
|
|
20
|
+
},
|
|
21
|
+
production: {
|
|
22
|
+
directory: "enhance",
|
|
23
|
+
macDirectory: "Enhance",
|
|
24
|
+
command: "enhance auth login"
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const tokenIn = (file) => {
|
|
28
|
+
try {
|
|
29
|
+
const saved = JSON.parse(readFileSync(file, "utf8"));
|
|
30
|
+
const token = typeof saved === "object" && saved !== null ? Reflect.get(saved, "token") : null;
|
|
31
|
+
return typeof token === "string" && token.trim() !== "" ? token : null;
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Where the CLI keeps its sign-in, first place first. On a Mac it saves in the person's
|
|
38
|
+
* Application Support folder, and an earlier CLI saved under ~/.config, which is still read.
|
|
39
|
+
*/
|
|
40
|
+
const cliSignInFiles = (environment) => {
|
|
41
|
+
const { directory, macDirectory } = cliSignIns[environment];
|
|
42
|
+
const earlier = nodePath.join(homedir(), ".config", directory, "credentials.json");
|
|
43
|
+
return process.platform === "darwin" ? [nodePath.join(homedir(), "Library", "Application Support", macDirectory, "credentials.json"), earlier] : [earlier];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* The token the CLI saved for this environment's own API, or null. A custom API URL never gets
|
|
47
|
+
* it, and neither does another environment: a development run never sends a production token.
|
|
48
|
+
*/
|
|
49
|
+
const cliToken = (environment, apiUrl) => {
|
|
50
|
+
if (environment === "local" || URL.parse(apiUrl)?.origin !== endpoints[environment]) return null;
|
|
51
|
+
for (const file of cliSignInFiles(environment)) {
|
|
52
|
+
const token = tokenIn(file);
|
|
53
|
+
if (token !== null) return token;
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
};
|
|
57
|
+
const noToken = (environment) => captureError("configuration", environment === "local" ? "Enhance needs a token: set ENHANCE_TOKEN or pass token." : `Enhance needs a token: set ENHANCE_TOKEN, pass token, or sign in with \`${cliSignIns[environment].command}\`.`);
|
|
58
|
+
const captureConnection = (options) => {
|
|
59
|
+
const selected = options.environment ?? process.env["ENHANCE_ENVIRONMENT"];
|
|
60
|
+
if (selected !== void 0 && selected !== "local" && selected !== "development" && selected !== "production") throw captureError("configuration", "ENHANCE_ENVIRONMENT must be local, development, or production.");
|
|
61
|
+
const environment = selected ?? (version.includes("-dev.") ? "development" : "production");
|
|
62
|
+
const apiUrl = options.apiUrl ?? process.env["ENHANCE_API_URL"] ?? endpoints[environment];
|
|
63
|
+
if (selected !== void 0) {
|
|
64
|
+
const url = URL.parse(apiUrl);
|
|
65
|
+
if (!(url !== null && (environment === "local" ? [
|
|
66
|
+
"localhost",
|
|
67
|
+
"127.0.0.1",
|
|
68
|
+
"[::1]"
|
|
69
|
+
].includes(url.hostname) : url.origin === endpoints[environment]))) throw captureError("configuration", `The API URL does not match the ${environment} environment. Set its matching endpoint or remove the explicit environment to use a custom API.`);
|
|
70
|
+
}
|
|
71
|
+
const token = options.token ?? process.env["ENHANCE_TOKEN"] ?? cliToken(environment, apiUrl);
|
|
72
|
+
if (token === null) throw noToken(environment);
|
|
73
|
+
return {
|
|
74
|
+
apiUrl,
|
|
75
|
+
token
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const createEnhance = (options = {}) => createEnhance$1({
|
|
79
|
+
...options,
|
|
80
|
+
...captureConnection(options)
|
|
81
|
+
});
|
|
82
|
+
//#endregion
|
|
83
|
+
export { createEnhance as t };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { A as captureSelection, M as selectedCaptures, V as captureManifestSchema, j as mergeCaptureManifests, z as captureArtifactSchema } from "./stall-watch.lib-
|
|
2
|
-
import { t as createEnhance } from "./environment.config-
|
|
1
|
+
import { A as captureSelection, M as selectedCaptures, V as captureManifestSchema, j as mergeCaptureManifests, z as captureArtifactSchema } from "./stall-watch.lib-DL_Gnxep.mjs";
|
|
2
|
+
import { t as createEnhance } from "./environment.config-uvF4VFma.mjs";
|
|
3
3
|
export { captureArtifactSchema, captureManifestSchema, captureSelection, createEnhance, mergeCaptureManifests, selectedCaptures };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { D as fitCaptureNames, F as filesNotCopiedIssue, I as pageNotSettledIssue, N as canonicalCaptureJson, O as leftOutCapture, P as CAPTURE_LEFT_OUT_REASONS, S as captureError, _ as writeCapturePayload, a as requestOutcomeOf, b as captureFileDigest, c as isReplayAssetContentType, d as captureDiagnostics, f as placeCaptureFile, h as writeCaptureBlob, i as requestFailureOfTransfer, l as inlineDataAssetReference, n as retrying, r as requestFailureOfReply, s as collectCssAssetUrls, t as startStallWatch, u as captureBlobPath, v as writeCaptureStream, y as captureBlobDigest, z as captureArtifactSchema } from "../stall-watch.lib-
|
|
2
|
-
import { t as version } from "../package-
|
|
3
|
-
import { n as awaitCaptureRun, r as captureContextDirectory, t as LEFT_OUT_ATTACHMENT } from "../capture-context.lib-
|
|
4
|
-
import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
5
|
-
import nodePath from "node:path";
|
|
1
|
+
import { D as fitCaptureNames, F as filesNotCopiedIssue, I as pageNotSettledIssue, N as canonicalCaptureJson, O as leftOutCapture, P as CAPTURE_LEFT_OUT_REASONS, S as captureError, _ as writeCapturePayload, a as requestOutcomeOf, b as captureFileDigest, c as isReplayAssetContentType, d as captureDiagnostics, f as placeCaptureFile, h as writeCaptureBlob, i as requestFailureOfTransfer, l as inlineDataAssetReference, n as retrying, r as requestFailureOfReply, s as collectCssAssetUrls, t as startStallWatch, u as captureBlobPath, v as writeCaptureStream, y as captureBlobDigest, z as captureArtifactSchema } from "../stall-watch.lib-DL_Gnxep.mjs";
|
|
2
|
+
import { t as version } from "../package-362fShMl.mjs";
|
|
3
|
+
import { n as awaitCaptureRun, r as captureContextDirectory, t as LEFT_OUT_ATTACHMENT } from "../capture-context.lib-DQn7JA02.mjs";
|
|
6
4
|
import { openAsBlob } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import nodePath from "node:path";
|
|
7
|
+
import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
7
8
|
import { test } from "@playwright/test";
|
|
8
9
|
import { Buffer as Buffer$1 } from "node:buffer";
|
|
9
10
|
import { Agent } from "undici";
|
|
10
|
-
import { tmpdir } from "node:os";
|
|
11
11
|
const CHROMIUM_LIMITS = {
|
|
12
12
|
width: 16384,
|
|
13
13
|
area: 32e6
|
|
@@ -32,6 +32,11 @@ const HEX = 16;
|
|
|
32
32
|
/** The hex SHA-256 of `body`, the checksum a checksum-signed upload is held to. */
|
|
33
33
|
const sha256Hex = async (body) => [...new Uint8Array(await crypto.subtle.digest("SHA-256", await body.arrayBuffer()))].map((byte) => byte.toString(HEX).padStart(2, "0")).join("");
|
|
34
34
|
//#endregion
|
|
35
|
+
//#region ../capture-browser/src/captured-local-fonts.lib.ts
|
|
36
|
+
const LOCAL_FONT_ADDRESS = "https://local-fonts.invalid/";
|
|
37
|
+
/** Whether an address is one a capture gave an installed font, which no server answers. */
|
|
38
|
+
const isLocalFontAddress = (url) => url.startsWith(LOCAL_FONT_ADDRESS);
|
|
39
|
+
//#endregion
|
|
35
40
|
//#region ../capture-browser/src/inline-assets.lib.ts
|
|
36
41
|
const rememberInlineAssets = (value, inlineAssets) => {
|
|
37
42
|
if (typeof value === "string") {
|
|
@@ -391,6 +396,22 @@ const mirrorAssetCopySession = (deps) => {
|
|
|
391
396
|
};
|
|
392
397
|
};
|
|
393
398
|
//#endregion
|
|
399
|
+
//#region ../capture-browser/src/captured-files.lib.ts
|
|
400
|
+
/**
|
|
401
|
+
* A stylesheet file of a whole-page capture, frozen where the live window can still answer. The
|
|
402
|
+
* stored page is laid out in a window as tall as the page, so a file sent as it was read would
|
|
403
|
+
* size its viewport units and answer its media conditions against that taller window.
|
|
404
|
+
*/
|
|
405
|
+
const frozenStylesheet = async (file, freeze) => {
|
|
406
|
+
if (freeze === void 0 || !file.contentType.toLowerCase().startsWith("text/css")) return file;
|
|
407
|
+
const text = await file.body.text();
|
|
408
|
+
const frozen = await freeze(text);
|
|
409
|
+
return frozen === text ? file : {
|
|
410
|
+
...file,
|
|
411
|
+
body: new Blob([frozen], { type: file.contentType })
|
|
412
|
+
};
|
|
413
|
+
};
|
|
414
|
+
//#endregion
|
|
394
415
|
//#region src/playwright/capture-assets.lib.ts
|
|
395
416
|
/** Files fetched at once: the connections a browser opens to one host. */
|
|
396
417
|
const FETCHES_AT_ONCE = 6;
|
|
@@ -537,6 +558,18 @@ const resourceReader = (page, on, written) => {
|
|
|
537
558
|
}
|
|
538
559
|
});
|
|
539
560
|
};
|
|
561
|
+
/** An installed font has no server: its address is answered by the page that can read it. */
|
|
562
|
+
const fontTaken = async (url, fontFile) => {
|
|
563
|
+
const font = await fontFile?.(url);
|
|
564
|
+
return font === void 0 || font === null ? {
|
|
565
|
+
url,
|
|
566
|
+
reason: "fetch_error"
|
|
567
|
+
} : {
|
|
568
|
+
url,
|
|
569
|
+
contentType: font.contentType,
|
|
570
|
+
body: new Blob([Buffer.from(font.base64, "base64")], { type: font.contentType })
|
|
571
|
+
};
|
|
572
|
+
};
|
|
540
573
|
/**
|
|
541
574
|
* Copies the files a captured screen names into the capture folder. One that will not come, or
|
|
542
575
|
* that cannot be written to disk, is left out and counted; there is no limit on the whole copy.
|
|
@@ -547,14 +580,17 @@ const retainedAssets = async (page, screen, on) => {
|
|
|
547
580
|
const inlineAssets = /* @__PURE__ */ new Map();
|
|
548
581
|
rememberInlineAssets(JSON.parse(screen.artifact), inlineAssets);
|
|
549
582
|
const dispatcher = new Agent(on.request?.ignoreHTTPSErrors === true ? { connect: { rejectUnauthorized: false } } : {});
|
|
550
|
-
const
|
|
583
|
+
const read = inlineAwareTake({ take: resourceReader(page, {
|
|
551
584
|
...on,
|
|
552
585
|
dispatcher
|
|
553
586
|
}, written) }, inlineAssets);
|
|
587
|
+
const take = async (url, signal) => isLocalFontAddress(url) ? fontTaken(url, on.fontFile) : read(url, signal);
|
|
554
588
|
const session = mirrorAssetCopySession({
|
|
555
589
|
take: async (url, signal) => {
|
|
556
|
-
const
|
|
557
|
-
if ("reason" in
|
|
590
|
+
const fetched = await take(url, signal);
|
|
591
|
+
if ("reason" in fetched) return fetched;
|
|
592
|
+
const taken = await frozenStylesheet(fetched, on.freezeStylesheet);
|
|
593
|
+
if (taken === fetched && written.has(url)) return taken;
|
|
558
594
|
const bytes = new Uint8Array(await taken.body.arrayBuffer());
|
|
559
595
|
const blob = {
|
|
560
596
|
sha256: captureBlobDigest(bytes),
|
|
@@ -690,6 +726,74 @@ const joinedShot = async (shot, directory) => {
|
|
|
690
726
|
}
|
|
691
727
|
};
|
|
692
728
|
//#endregion
|
|
729
|
+
//#region src/playwright/capture-font-access.lib.ts
|
|
730
|
+
const FONTS_PERMISSION = { name: "local-fonts" };
|
|
731
|
+
/**
|
|
732
|
+
* Grants the page's site the permission to read installed fonts, when the test has not decided it,
|
|
733
|
+
* and answers with how to set it back. Null when nothing was changed: the test granted or refused
|
|
734
|
+
* it already, or this browser will not grant it, and then the capture names the fonts not sent.
|
|
735
|
+
*/
|
|
736
|
+
const grantedFonts = async (page, origin) => {
|
|
737
|
+
try {
|
|
738
|
+
if (await page.evaluate("navigator.permissions.query({ name: 'local-fonts' }).then((status) => status.state)") !== "prompt") return null;
|
|
739
|
+
const session = await page.context().newCDPSession(page);
|
|
740
|
+
const { targetInfo } = await session.send("Target.getTargetInfo");
|
|
741
|
+
const { browserContextId } = targetInfo;
|
|
742
|
+
const permission = {
|
|
743
|
+
permission: FONTS_PERMISSION,
|
|
744
|
+
origin,
|
|
745
|
+
...browserContextId !== void 0 && { browserContextId }
|
|
746
|
+
};
|
|
747
|
+
await session.send("Browser.setPermission", {
|
|
748
|
+
...permission,
|
|
749
|
+
setting: "granted"
|
|
750
|
+
});
|
|
751
|
+
return async () => {
|
|
752
|
+
await session.send("Browser.setPermission", {
|
|
753
|
+
...permission,
|
|
754
|
+
setting: "prompt"
|
|
755
|
+
});
|
|
756
|
+
await session.detach();
|
|
757
|
+
};
|
|
758
|
+
} catch {
|
|
759
|
+
return null;
|
|
760
|
+
}
|
|
761
|
+
};
|
|
762
|
+
/**
|
|
763
|
+
* Lets the page read the fonts installed on this machine while `work` runs, and leaves the
|
|
764
|
+
* permission as the test had it. Nobody is at a test's browser to answer its question. Only this
|
|
765
|
+
* permission of this page's site changes: Playwright's own grant denies every permission the test
|
|
766
|
+
* has not granted, and a test that captures must not differ from one that does not.
|
|
767
|
+
*/
|
|
768
|
+
const withInstalledFonts = async (page, work) => {
|
|
769
|
+
const origin = URL.parse(page.url())?.origin ?? "null";
|
|
770
|
+
if (origin === "null" || page.context().browser()?.browserType().name() !== "chromium") return work();
|
|
771
|
+
const setBack = await grantedFonts(page, origin);
|
|
772
|
+
try {
|
|
773
|
+
return await work();
|
|
774
|
+
} finally {
|
|
775
|
+
await setBack?.();
|
|
776
|
+
}
|
|
777
|
+
};
|
|
778
|
+
//#endregion
|
|
779
|
+
//#region src/playwright/capture-kernel.lib.ts
|
|
780
|
+
const pageKernel = async (page, options) => {
|
|
781
|
+
const kernel = await readFile(new URL(import.meta.resolve("#capture-kernel")), "utf8");
|
|
782
|
+
const run = async (call) => page.evaluate(`(function() { ${kernel}\n return __enhance_capture_kernel__.${call}; })()`);
|
|
783
|
+
const freeze = JSON.stringify({
|
|
784
|
+
extent: options.extent ?? "viewport",
|
|
785
|
+
...options.blockSelector !== void 0 && { blockSelector: options.blockSelector }
|
|
786
|
+
});
|
|
787
|
+
return {
|
|
788
|
+
capture: async () => run(`freezeCapturedPage(document, ${freeze}).then(function (frozen) { return frozen.screen; })`),
|
|
789
|
+
extent: async () => options.extent === "full-page" ? run("fullPageCaptureLayout(document, () => 0).viewport") : page.evaluate("({ width: document.documentElement.clientWidth, height: document.documentElement.clientHeight })"),
|
|
790
|
+
openForPicture: async () => run("openForPicture(document)"),
|
|
791
|
+
closeAfterPicture: async () => run("closeAfterPicture()"),
|
|
792
|
+
freezeStylesheet: async (css) => run(`fullPageStylesheetFreeze(document)(${JSON.stringify(css)})`),
|
|
793
|
+
fontFile: async (url) => run(`localFontFileBase64(document, ${JSON.stringify(url)})`)
|
|
794
|
+
};
|
|
795
|
+
};
|
|
796
|
+
//#endregion
|
|
693
797
|
//#region src/playwright/capture-page.lib.ts
|
|
694
798
|
/** How long the SDK looks for a pass that settles; it decides only whether to start another. */
|
|
695
799
|
const CAPTURE_STABILITY_MS = 5e3;
|
|
@@ -722,31 +826,18 @@ const descriptor = (bytes, mediaType) => ({
|
|
|
722
826
|
mediaType
|
|
723
827
|
});
|
|
724
828
|
const isSameSize = (left, right) => left.width === right.width && left.height === right.height;
|
|
725
|
-
const pageKernel = async (page, options) => {
|
|
726
|
-
const kernel = await readFile(new URL(import.meta.resolve("#capture-kernel")), "utf8");
|
|
727
|
-
const run = async (call) => page.evaluate(`(function() { ${kernel}\n return __enhance_capture_kernel__.${call}; })()`);
|
|
728
|
-
return {
|
|
729
|
-
capture: async () => run(`captureBrowserScreen(document, ${JSON.stringify({
|
|
730
|
-
extent: options.extent ?? "viewport",
|
|
731
|
-
...options.blockSelector !== void 0 && { blockSelector: options.blockSelector }
|
|
732
|
-
})})`),
|
|
733
|
-
/** The size the snapshot records: the full page, a panel that scrolls inside it included. */
|
|
734
|
-
extent: async () => options.extent === "full-page" ? run("fullPageCaptureLayout(document, () => 0).viewport") : page.evaluate("({ width: document.documentElement.clientWidth, height: document.documentElement.clientHeight })")
|
|
735
|
-
};
|
|
736
|
-
};
|
|
737
829
|
/**
|
|
738
|
-
* One path for every page: the window
|
|
739
|
-
* clipped to
|
|
740
|
-
*
|
|
741
|
-
*
|
|
830
|
+
* One path for every page: the window keeps the size the test gave it, every screenshot is
|
|
831
|
+
* clipped to the size the snapshot records, and a page is kept once three snapshots and two
|
|
832
|
+
* screenshots in one pass agree. A whole page is pictured beyond the window's edge, under the
|
|
833
|
+
* rules its stored page carries, so nothing sized by the window is laid out again. A page that
|
|
834
|
+
* never settles is captured at its final moment and named.
|
|
742
835
|
*/
|
|
743
|
-
const stableScreen = async (page, options) => {
|
|
744
|
-
const kernel = await pageKernel(page, options);
|
|
836
|
+
const stableScreen = async (page, options, kernel) => {
|
|
745
837
|
const isFullPage = options.extent === "full-page";
|
|
746
|
-
const window = page.viewportSize();
|
|
747
838
|
const shoot = async (band) => page.screenshot({
|
|
748
839
|
type: "png",
|
|
749
|
-
fullPage:
|
|
840
|
+
fullPage: isFullPage,
|
|
750
841
|
clip: band,
|
|
751
842
|
animations: "disabled",
|
|
752
843
|
caret: "hide",
|
|
@@ -757,43 +848,43 @@ const stableScreen = async (page, options) => {
|
|
|
757
848
|
maskColor: "#d8d8d8"
|
|
758
849
|
}
|
|
759
850
|
});
|
|
760
|
-
const
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
851
|
+
const pictured = async (size) => {
|
|
852
|
+
if (!isFullPage) return shotInBands(size, shoot);
|
|
853
|
+
await kernel.openForPicture();
|
|
854
|
+
try {
|
|
855
|
+
return await shotInBands(size, shoot);
|
|
856
|
+
} finally {
|
|
857
|
+
await kernel.closeAfterPicture();
|
|
858
|
+
}
|
|
764
859
|
};
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
isSettled
|
|
782
|
-
};
|
|
783
|
-
await discardShot(second);
|
|
784
|
-
} while (Date.now() < deadline || passes < LEAST_PASSES);
|
|
785
|
-
const final = await kernel.capture();
|
|
786
|
-
return {
|
|
787
|
-
screen: final,
|
|
788
|
-
shot: await shotInBands(await sized({
|
|
789
|
-
width: final.viewport.width,
|
|
790
|
-
height: final.viewport.height
|
|
791
|
-
}), shoot),
|
|
792
|
-
isSettled: false
|
|
860
|
+
const deadline = Date.now() + CAPTURE_STABILITY_MS;
|
|
861
|
+
let passes = 0;
|
|
862
|
+
do {
|
|
863
|
+
const extent = await kernel.extent();
|
|
864
|
+
const before = await kernel.capture();
|
|
865
|
+
const first = await pictured(extent);
|
|
866
|
+
const middle = await kernel.capture();
|
|
867
|
+
const second = await pictured(extent);
|
|
868
|
+
const after = await kernel.capture();
|
|
869
|
+
passes++;
|
|
870
|
+
const isSettled = sourceSignature(before) === sourceSignature(middle) && sourceSignature(middle) === sourceSignature(after) && isSameSize(middle.viewport, extent) && isSameShot(first, second);
|
|
871
|
+
await discardShot(first);
|
|
872
|
+
if (isSettled) return {
|
|
873
|
+
screen: middle,
|
|
874
|
+
shot: second,
|
|
875
|
+
isSettled
|
|
793
876
|
};
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
877
|
+
await discardShot(second);
|
|
878
|
+
} while (Date.now() < deadline || passes < LEAST_PASSES);
|
|
879
|
+
const final = await kernel.capture();
|
|
880
|
+
return {
|
|
881
|
+
screen: final,
|
|
882
|
+
shot: await pictured({
|
|
883
|
+
width: final.viewport.width,
|
|
884
|
+
height: final.viewport.height
|
|
885
|
+
}),
|
|
886
|
+
isSettled: false
|
|
887
|
+
};
|
|
797
888
|
};
|
|
798
889
|
const pngSize = (bytes) => {
|
|
799
890
|
if (bytes.length < PNG_HEADER_BYTES || bytes.toString("hex", 0, PNG_SIGNATURE_BYTES) !== "89504e470d0a1a0a") throw captureError("capture", "The browser did not return a PNG preview.");
|
|
@@ -827,15 +918,29 @@ const capturePage = async (page, options, context) => {
|
|
|
827
918
|
step: options.step,
|
|
828
919
|
variant: options.variant ?? context.variant
|
|
829
920
|
};
|
|
830
|
-
const
|
|
831
|
-
const
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
921
|
+
const kernel = await pageKernel(page, options);
|
|
922
|
+
const kept = await withInstalledFonts(page, async () => {
|
|
923
|
+
const captured = await stableScreen(page, options, kernel);
|
|
924
|
+
const preview = await savedPreview(captured.shot, context.directory);
|
|
925
|
+
const sourceBytes = Buffer$1.from(captured.screen.artifact, "utf8");
|
|
926
|
+
const source = descriptor(sourceBytes, "application/json");
|
|
927
|
+
if (preview === null || !await writeCaptureBlob(context.directory, source, sourceBytes)) return null;
|
|
928
|
+
return {
|
|
929
|
+
captured,
|
|
930
|
+
preview,
|
|
931
|
+
source,
|
|
932
|
+
retained: await retainedAssets(page, captured.screen, {
|
|
933
|
+
...context,
|
|
934
|
+
fontFile: kernel.fontFile,
|
|
935
|
+
...options.extent === "full-page" && { freezeStylesheet: kernel.freezeStylesheet }
|
|
936
|
+
})
|
|
937
|
+
};
|
|
938
|
+
});
|
|
939
|
+
if (kept === null) return {
|
|
835
940
|
key,
|
|
836
941
|
message: CAPTURE_LEFT_OUT_REASONS.notSaved
|
|
837
942
|
};
|
|
838
|
-
const
|
|
943
|
+
const { captured, preview, source, retained } = kept;
|
|
839
944
|
return { artifact: {
|
|
840
945
|
format: "enhance-capture",
|
|
841
946
|
version: 1,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { B as captureLeftOutSchema, C as isCaptureError, D as fitCaptureNames, O as leftOutCapture, P as CAPTURE_LEFT_OUT_REASONS, d as captureDiagnostics, g as writeCaptureJson, z as captureArtifactSchema } from "../stall-watch.lib-
|
|
2
|
-
import { t as createEnhance } from "../environment.config-
|
|
3
|
-
import { i as setCaptureDirectory } from "../capture-context.lib-
|
|
1
|
+
import { B as captureLeftOutSchema, C as isCaptureError, D as fitCaptureNames, O as leftOutCapture, P as CAPTURE_LEFT_OUT_REASONS, d as captureDiagnostics, g as writeCaptureJson, z as captureArtifactSchema } from "../stall-watch.lib-DL_Gnxep.mjs";
|
|
2
|
+
import { t as createEnhance } from "../environment.config-uvF4VFma.mjs";
|
|
3
|
+
import { i as setCaptureDirectory } from "../capture-context.lib-DQn7JA02.mjs";
|
|
4
|
+
import nodePath from "node:path";
|
|
4
5
|
import process from "node:process";
|
|
5
6
|
import { mkdir, readFile } from "node:fs/promises";
|
|
6
|
-
import nodePath from "node:path";
|
|
7
7
|
//#region src/playwright/capture-reporter.lib.ts
|
|
8
8
|
const errorOf = (error) => error instanceof Error ? error : /* @__PURE__ */ new Error("Enhance reporter could not complete the capture run.");
|
|
9
9
|
const initialize = async (session) => {
|