Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for getting webSocketDebuggerUrl from /json/version #2042

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
23 changes: 17 additions & 6 deletions apps/server/src/printer/printer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ErrorMessage, getFontUrls } from "@reactive-resume/utils";
import retry from "async-retry";
import { PDFDocument } from "pdf-lib";
import { connect } from "puppeteer";
import { firstValueFrom } from "rxjs";

import { Config } from "../config/schema";
import { StorageService } from "../storage/storage.service";
Expand All @@ -15,7 +16,9 @@ import { StorageService } from "../storage/storage.service";
export class PrinterService {
private readonly logger = new Logger(PrinterService.name);

private readonly browserURL: string;
private readonly chromeUrl: string;

private readonly chromeToken: string;

private readonly ignoreHTTPSErrors: boolean;

Expand All @@ -24,20 +27,28 @@ export class PrinterService {
private readonly storageService: StorageService,
private readonly httpService: HttpService,
) {
const chromeUrl = this.configService.getOrThrow<string>("CHROME_URL");
const chromeToken = this.configService.getOrThrow<string>("CHROME_TOKEN");

this.browserURL = `${chromeUrl}?token=${chromeToken}`;
this.chromeUrl = this.configService.getOrThrow<string>("CHROME_URL");
this.chromeToken = this.configService.getOrThrow<string>("CHROME_TOKEN");
this.ignoreHTTPSErrors = this.configService.getOrThrow<boolean>("CHROME_IGNORE_HTTPS_ERRORS");
}

private async getBrowser() {
let browserURL;

try {
if (this.chromeUrl.endsWith("/json/version")) {
const res = await firstValueFrom(this.httpService.get(this.chromeUrl));
browserURL = `${res.data.webSocketDebuggerUrl}?token=${this.chromeToken}`;
} else {
browserURL = `${this.chromeUrl}?token=${this.chromeToken}`;
}

return await connect({
browserWSEndpoint: this.browserURL,
browserWSEndpoint: browserURL,
acceptInsecureCerts: this.ignoreHTTPSErrors,
});
} catch (error) {
console.debug("browserURL:", !browserURL);
throw new InternalServerErrorException(
ErrorMessage.InvalidBrowserConnection,
(error as Error).message,
Expand Down