Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default (): Env => {
CURRENT_BRANCH,
PROJECT_NAME,
SMARTUI_API_PROXY,
SMARTUI_API_SKIP_CERTIFICATES
SMARTUI_API_SKIP_CERTIFICATES,
SMARTUI_PAGE_WAIT_UNTIL_EVENT
} = process.env

return {
Expand All @@ -40,6 +41,7 @@ export default (): Env => {
SMARTUI_DO_NOT_USE_CAPTURED_COOKIES: SMARTUI_DO_NOT_USE_CAPTURED_COOKIES === 'true',
PROJECT_NAME,
SMARTUI_API_PROXY,
SMARTUI_API_SKIP_CERTIFICATES: SMARTUI_API_SKIP_CERTIFICATES === 'true'
SMARTUI_API_SKIP_CERTIFICATES: SMARTUI_API_SKIP_CERTIFICATES === 'true',
SMARTUI_PAGE_WAIT_UNTIL_EVENT,
}
}
22 changes: 19 additions & 3 deletions src/lib/processSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,29 @@ export default async function processSnapshot(snapshot: Snapshot, ctx: Context):
await page.setViewportSize({ width: viewport.width, height: viewport.height || MIN_VIEWPORT_HEIGHT });
ctx.log.debug(`Page resized to ${viewport.width}x${viewport.height || MIN_VIEWPORT_HEIGHT}`);

type WaitUntilOption = 'load' | 'domcontentloaded';

const envWaitUntil = ctx.env.SMARTUI_PAGE_WAIT_UNTIL_EVENT;

// Check if the environment value is valid
const waitUntil: WaitUntilOption =
(envWaitUntil === 'load' || envWaitUntil === 'domcontentloaded')
? (envWaitUntil as WaitUntilOption)
: 'domcontentloaded';


ctx.log.debug(`Wait until: ${waitUntil}`);

// navigate to snapshot url once
if (!navigated) {
try {
// domcontentloaded event is more reliable than load event
await page.goto(snapshot.url, { waitUntil: "domcontentloaded", timeout: ctx.config.waitForDiscovery });
// adding extra timeout since domcontentloaded event is fired pretty quickly
await new Promise(r => setTimeout(r, 1250));
await page.goto(snapshot.url, {waitUntil: waitUntil, timeout: ctx.config.waitForDiscovery});
if (waitUntil === 'domcontentloaded') {
// adding extra timeout since domcontentloaded event is fired pretty quickly
ctx.log.debug(`Waiting for 1250 ms since waiting for ${waitUntil}`);
await new Promise(r => setTimeout(r, 1250));
}
if (ctx.config.waitForTimeout) await page.waitForTimeout(ctx.config.waitForTimeout);
navigated = true;
ctx.log.debug(`Navigated to ${snapshot.url}`);
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export interface Env {
PROJECT_NAME: string | undefined;
SMARTUI_API_PROXY: string | undefined;
SMARTUI_API_SKIP_CERTIFICATES: boolean;
SMARTUI_PAGE_WAIT_UNTIL_EVENT: string | undefined;
}

export interface Snapshot {
Expand Down