diff --git a/src/handlers/handler-input.ts b/src/handlers/handler-input.ts index 1f2d260..7c7693e 100644 --- a/src/handlers/handler-input.ts +++ b/src/handlers/handler-input.ts @@ -7,6 +7,7 @@ export class HandlerInput { private requestUrl: URL; private engine?: string; private redirectPath: string; + private dom?: JSDOM; constructor( data: string, @@ -23,9 +24,13 @@ export class HandlerInput { } parseDom(): JSDOM { - const dom = new JSDOM(this.data, { url: this.url }); + if (this.dom) { + return this.dom; + } + + this.dom = new JSDOM(this.data, { url: this.url }); - const links = dom.window.document.getElementsByTagName("a"); + const links = this.dom.window.document.getElementsByTagName("a"); for (const link of links) { try { link.href = generateProxyUrl( @@ -39,7 +44,7 @@ export class HandlerInput { } } - return dom; + return this.dom; } getUrl(): string {