do not pass browser instance to content-handler

This commit is contained in:
Hongbo Wu
2024-05-13 13:10:02 +08:00
parent 86e637febd
commit 0ac5299c32
4 changed files with 4 additions and 9 deletions

View File

@ -36,7 +36,6 @@
"linkedom": "^0.14.16",
"lodash": "^4.17.21",
"luxon": "^3.0.4",
"puppeteer-core": "^20.9.0",
"underscore": "^1.13.6",
"uuid": "^9.0.0"
},

View File

@ -1,7 +1,6 @@
import addressparser from 'addressparser'
import axios from 'axios'
import { parseHTML } from 'linkedom'
import { Browser } from 'puppeteer-core'
import { v4 as uuid } from 'uuid'
interface Unsubscribe {
@ -61,7 +60,7 @@ export abstract class ContentHandler {
return false
}
async preHandle(url: string, browser?: Browser): Promise<PreHandleResult> {
async preHandle(url: string): Promise<PreHandleResult> {
return Promise.resolve({ url })
}

View File

@ -1,5 +1,4 @@
import { parseHTML } from 'linkedom'
import { Browser } from 'puppeteer-core'
import {
ContentHandler,
NewsletterInput,
@ -104,8 +103,7 @@ const newsletterHandlers: ContentHandler[] = [
]
export const preHandleContent = async (
url: string,
browser: Browser
url: string
): Promise<PreHandleResult | undefined> => {
// Before we run the regular handlers we check to see if we need tp
// pre-resolve the URL. TODO: This should probably happen recursively,
@ -129,7 +127,7 @@ export const preHandleContent = async (
for (const handler of contentHandlers) {
if (handler.shouldPreHandle(url)) {
console.log('preHandleContent', handler.name, url)
return handler.preHandle(url, browser)
return handler.preHandle(url)
}
}
return undefined

View File

@ -163,8 +163,7 @@ export const fetchContent = async (
// pre handle url with custom handlers
try {
const browser = await getBrowserPromise
const result = await preHandleContent(url, browser)
const result = await preHandleContent(url)
if (result && result.url) {
validateUrlString(url)
url = result.url