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", 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')));