Skip to content

Commit

Permalink
fix: issues loading cnn and other sites + performance improvements (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
fukouda authored Dec 5, 2024
1 parent afac766 commit 26497ad
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions api/src/modules/actions/actions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const handleScreenshot = async (browserService: CDPService, request: Scre
page = await browserService.getPrimaryPage();
}
times.pageTime = Date.now() - startTime;
await page.goto(url);
await page.goto(url, { timeout: 30000, waitUntil: "domcontentloaded" });
times.pageLoadTime = Date.now() - times.pageTime - times.proxyTime - startTime;

if (delay) {
Expand Down Expand Up @@ -205,7 +205,7 @@ export const handlePDF = async (browserService: CDPService, request: PDFRequest,
page = await browserService.getPrimaryPage();
}
times.pageTime = Date.now() - startTime;
await page.goto(url);
await page.goto(url, { timeout: 30000, waitUntil: "domcontentloaded" });
times.pageLoadTime = Date.now() - times.pageTime - times.proxyTime - startTime;

if (delay) {
Expand Down
2 changes: 1 addition & 1 deletion api/src/modules/sessions/sessions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const handleLaunchBrowserSession = async (

const browserLauncherOptions: BrowserLauncherOptions = {
options: {
headless: false,
headless: true,
args: [userAgent ? `--user-agent=${userAgent}` : undefined].filter(Boolean) as string[],
proxyUrl,
},
Expand Down
13 changes: 7 additions & 6 deletions api/src/services/cdp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class CDPService extends EventEmitter {
this.currentSessionConfig = null;
this.shuttingDown = false;
this.defaultLaunchConfig = {
options: { headless: false },
options: { headless: true },
};
}

Expand Down Expand Up @@ -234,9 +234,12 @@ export class CDPService extends EventEmitter {

const cdpSession = await page.createCDPSession();

const currentViewport = await page.viewport();

const { width, height } = this.launchConfig?.dimensions || { width: 1920, height: 1080 };
if (this.launchConfig?.dimensions) {
this.logger.info("Setting viewport to", width, height);

this.logger.info("Setting viewport to", width, height);
if (!currentViewport || currentViewport.width !== width || currentViewport.height !== height) {
await page.setViewport({ width, height });
await (
await page.createCDPSession()
Expand All @@ -256,8 +259,6 @@ export class CDPService extends EventEmitter {
cdpSession.removeAllListeners();
});

// await installMouseHelper(page);

const updateLocalStorage = (host: string, storage: Record<string, string>) => {
this.localStorageData[host] = { ...this.localStorageData[host], ...storage };
};
Expand Down Expand Up @@ -370,7 +371,7 @@ export class CDPService extends EventEmitter {

const finalLaunchOptions = {
...options,
defaultViewport: this.launchConfig.dimensions ? this.launchConfig.dimensions : undefined,
defaultViewport: this.launchConfig.dimensions ? this.launchConfig.dimensions : null,
args: launchArgs,
executablePath: this.chromeExecPath,
timeout: 0,
Expand Down

0 comments on commit 26497ad

Please sign in to comment.