Skip to content

Commit

Permalink
Track error removed for html generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Jun 30, 2023
1 parent 9a019ab commit 55519d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/commands/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,24 @@ export default abstract class Command {
event.page = page;

// page.on("pageerror", (e) => this.pageError = e );
this.TrackError(page);

// if it is html...
// disable image/css/font/video...
await this.interceptResourceLoader(event);

if (url) {
await page.goto(url, { waitUntil: "networkidle2" });
console.log(`Url loaded.`);
} else {
await page.setContent(content, { waitUntil: "networkidle2"});
console.log(`Content loaded.`);
}

await this.waitForPageToLoad(event);
}

protected TrackError(page: Page) {
page.on("requestfailed", (e) => {
if (e.response()?.status() <= 409) {
return;
Expand All @@ -184,21 +202,7 @@ export default abstract class Command {
} catch (error) {
console.error(error);
}
})

// if it is html...
// disable image/css/font/video...
await this.interceptResourceLoader(event);

if (url) {
await page.goto(url, { waitUntil: "networkidle2" });
console.log(`Url loaded.`);
} else {
await page.setContent(content, { waitUntil: "networkidle2"});
console.log(`Content loaded.`);
}

await this.waitForPageToLoad(event);
});
}

async waitForPageToLoad({ timeout, page, stopTest }: IEvent) {
Expand Down
5 changes: 5 additions & 0 deletions src/commands/GenerateHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { writeFileSync } from "fs";
import { IEvent } from "../IEvent";
import Command from "./Command";
import FlattenStyles from "./html/FlattenStyles";
import { Page } from "puppeteer-core";

export default class GenerateHtml extends Command {

Expand Down Expand Up @@ -32,6 +33,10 @@ export default class GenerateHtml extends Command {
}
}

protected TrackError(page: Page): void {

}

async interceptResourceLoader({ page, flattenStyle }: IEvent) {
await page.setRequestInterception(true);
if (flattenStyle) {
Expand Down

0 comments on commit 55519d7

Please sign in to comment.