Skip to content

Commit

Permalink
fix pie always trigger the timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiram committed May 9, 2024
1 parent 5c34950 commit b7fa1c0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/utils/pie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const puppeteerInElectron = async (
snifferWindow.webContents.setAudioMuted(true); // 设置窗口静音

const page = await pie.getPage(browser, snifferWindow); // 获取页面
const pageRecord = { page, browser, timestamp: Date.now() / 1000, timeoutId: null };
const pageRecord = { page, browser, timestamp: Date.now() / 1000, timerId: null };
pageStore[pageId] = pageRecord; // 存储页面

if (ua) await page.setUserAgent(ua); // 设置ua
Expand All @@ -66,7 +66,7 @@ const puppeteerInElectron = async (
const cleanup = async (pageId: string) => {
if (pageId) {
if (pageStore[pageId]) {
if (pageStore[pageId]?.timeoutId) clearTimeout(pageStore[pageId].timeoutId);
if (pageStore[pageId]?.timerId) await clearTimeout(pageStore[pageId].timerId);
if (pageStore[pageId]?.page) await pageStore[pageId].page.close().catch((err) => logger.error(err));
if (pageStore[pageId]?.browser) await pageStore[pageId].browser.disconnect();
delete pageStore[pageId];
Expand Down Expand Up @@ -114,6 +114,7 @@ const puppeteerInElectron = async (
logger.info('--------!timerId---------');
pageStore[pageId].timerId = setTimeout(async () => {
await cleanup(pageId);
logger.info(`[pie]id: ${pageId} sniffer timeout`);
reject(handleResponse(500, 'fail', new Error('fail', { cause: 'sniffer timeout' })));
}, 15000);
} else {
Expand Down

0 comments on commit b7fa1c0

Please sign in to comment.