Skip to content

Commit

Permalink
cleaning up integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
AlfieJones committed May 22, 2024
1 parent d631711 commit 1c14c3d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
3 changes: 3 additions & 0 deletions integrations/cli/cli-capture/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "@pixeleye/tsconfig/node.json",
"include": ["."],
"compilerOptions": {
"lib": ["dom"]
},
"exclude": ["dist", "build", "node_modules"]
}
1 change: 1 addition & 0 deletions integrations/cypress/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const pixeleyeSnapshot = (options: Options) => {
const serializedDom = domSnapshot(doc, {
recordCanvas: true,
inlineImages: true,
inlineStylesheet: true,
});
if (!serializedDom) {
throw new Error("Failed to serialize DOM");
Expand Down
35 changes: 19 additions & 16 deletions integrations/puppeteer/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ import {
} from "@pixeleye/cli-booth";
import { createRequire } from "node:module";
import { snapshot as rrwebSnapshotFn } from "rrweb-snapshot";
import rrweb from "rrweb-snapshot";

type RRWeb = typeof rrweb;

let rrwebScript: string | undefined;
try {
rrwebScript = require.resolve("rrweb-snapshot/dist/rrweb-snapshot.min.js");
} catch {
const require = createRequire(import.meta.url);
rrwebScript = require.resolve("rrweb-snapshot/dist/rrweb-snapshot.min.js");
}

export interface Options {
fullPage?: boolean;
Expand All @@ -22,14 +33,6 @@ export interface Options {
wait?: number;
}

let rrwebSnapshot: string | undefined;
try {
rrwebSnapshot = require.resolve("rrweb-snapshot/dist/rrweb-snapshot.min.js");
} catch {
const require = createRequire(import.meta.url);
rrwebSnapshot = require.resolve("rrweb-snapshot/dist/rrweb-snapshot.min.js");
}

export async function pixeleyeSnapshot(
page: Page | PageCore,
options: Options
Expand Down Expand Up @@ -60,17 +63,17 @@ export async function pixeleyeSnapshot(
: undefined;

await (page as Page).addScriptTag({
path: rrwebSnapshot,
path: rrwebScript,
});

const domSnapshot = await (page as Page).evaluate(() => {
return ((rrwebSnapshot as any).snapshot as typeof rrwebSnapshotFn)(
document,
{
recordCanvas: true,
inlineImages: true,
}
);
const r: RRWeb = (window as any).rrwebSnapshot;

return r.snapshot(document, {
recordCanvas: true,
inlineImages: true,
inlineStylesheet: true,
});
});

if (!domSnapshot) {
Expand Down
3 changes: 3 additions & 0 deletions integrations/puppeteer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "@pixeleye/tsconfig/node.json",
"include": ["."],
"compilerOptions": {
"lib": ["dom"]
},
"exclude": ["dist", "build", "node_modules"]
}

0 comments on commit 1c14c3d

Please sign in to comment.