From 1552855aa993f2f2d01b17dae46c07ef30b5ef1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=9A=E9=A3=8E=E6=8B=82=E6=9F=B3=E9=A2=9C?= <434857005@qq.com> Date: Tue, 4 Jun 2024 01:27:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=97=85=E6=8E=A2?= =?UTF-8?q?=E8=BF=87=E7=A8=8B=E4=B8=AD=E8=8E=AB=E5=90=8D=E5=85=B6=E5=A6=99?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/utils/pie.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/utils/pie.ts b/src/main/utils/pie.ts index b3ef011b7..00a564f26 100644 --- a/src/main/utils/pie.ts +++ b/src/main/utils/pie.ts @@ -88,9 +88,10 @@ const puppeteerInElectron = async ( }; page.on('request', async (req) => { - if (req.isInterceptResolutionHandled()) return; // 已处理过的请求不再处理 - const reqUrl = req.url(); // 请求url + // logger.info(`[reqUrl]:${reqUrl}`); + if (req.isInterceptResolutionHandled()) return req.abort().catch((err) => logger.error(err)); // 已处理过的请求不再处理 + const reqHeaders = req.headers(); // 请求头 const { referer, 'user-agent': userAgent } = reqHeaders; const headers = {}; @@ -99,33 +100,38 @@ const puppeteerInElectron = async ( if (customRegex && reqUrl.match(new RegExp(customRegex, 'gi'))) { logger.info(`[pie]正则匹配:${reqUrl}`); + page.removeAllListeners("request"); await cleanup(pageId); req.abort().catch((e) => logger.error(e)); - resolve(handleResponse(200, 'success', { url: reqUrl, header: headers })); + return resolve(handleResponse(200, 'success', { url: reqUrl, header: headers })); } if (isVideoUrl(reqUrl)) { logger.info(`[pie]后缀名匹配:${reqUrl}`); + page.removeAllListeners("request"); await cleanup(pageId); req.abort().catch((e) => logger.error(e)); - resolve(handleResponse(200, 'success', { url: reqUrl, header: headers })); + return resolve(handleResponse(200, 'success', { url: reqUrl, header: headers })); } if (req.method().toLowerCase() === 'head') { - req.abort().catch((err) => logger.error(err)); + // logger.info(`[pie][head]:${reqUrl}`); + return req.abort().catch((err) => logger.error(err)); } - - if (['font'].includes(req.resourceType())) { - req.abort().catch((err) => logger.error(err)); + // + if (/\.(png|jpg|jpeg|ttf)$/.test(reqUrl) && ["stylesheet", "image", "font"].includes(req.resourceType())) { + // logger.info(`[pie][font]:${reqUrl}`); + return req.abort().catch((err) => logger.error(err)); } - req.continue().catch((err) => logger.error(err)); + return req.continue().catch((err) => logger.error(err)); }); // 设置超时 if (!pageStore[pageId].timerId) { logger.info('--------!timerId---------'); pageStore[pageId].timerId = setTimeout(async () => { + page.removeAllListeners("request"); await cleanup(pageId); logger.info(`[pie]id: ${pageId} sniffer timeout`); reject(handleResponse(500, 'fail', new Error('sniffer timeout'))); From 813c88ccf0b08b05954c6acdc7107ad682b25361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=9A=E9=A3=8E=E6=8B=82=E6=9F=B3=E9=A2=9C?= <434857005@qq.com> Date: Tue, 4 Jun 2024 01:41:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=97=85=E6=8E=A2?= =?UTF-8?q?=E5=BA=93=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4518aefbc..9e5811f6d 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "electron-updater": "^6.1.8", "fs-extra": "^11.2.0", "ip": "^2.0.1", - "puppeteer-core": "~20.0.0", + "puppeteer-core": "~21.3.8", "puppeteer-in-electron": "^3.0.5", "v8-compile-cache": "^2.4.0" }, @@ -79,7 +79,7 @@ "dashjs": "^4.7.4", "dayjs": "^1.11.11", "dplayer": "^1.27.1", - "electron": "^22.0.0", + "electron": "~22.3.27", "electron-builder": "^24.13.3", "electron-vite": "^2.2.0", "eslint": "^9.4.0",