From cdc01c46fbdfab8798304cc670de36b0d0e7a1b5 Mon Sep 17 00:00:00 2001 From: bossgeekgo Date: Tue, 13 Feb 2024 13:32:19 +0800 Subject: [PATCH] change the way for importing puppeteer to work with ui --- .../geek-auto-start-chat-with-boss/index.mjs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/geek-auto-start-chat-with-boss/index.mjs b/packages/geek-auto-start-chat-with-boss/index.mjs index c914bf7..2bc10a1 100644 --- a/packages/geek-auto-start-chat-with-boss/index.mjs +++ b/packages/geek-auto-start-chat-with-boss/index.mjs @@ -1,6 +1,3 @@ -import puppeteer from 'puppeteer-extra'; -import StealthPlugin from 'puppeteer-extra-plugin-stealth' - import { sleep, sleepWithRandomDelay @@ -14,7 +11,21 @@ import JSON5 from 'json5' import { readConfigFile, ensureConfigFileExist } from './runtime-file-utils.mjs' ensureConfigFileExist() -puppeteer.use(StealthPlugin()) +let puppeteer +async function initPuppeteer () { + const [ + puppeteerModule, + StealthPluginModule, + ] = await Promise.all( + [ + import('puppeteer-extra'), + import('puppeteer-extra-plugin-stealth') + ] + ) + + puppeteerModule.default.use(StealthPluginModule.default()) + puppeteer = puppeteerModule.default +} const { cookies: bossCookies } = readConfigFile('boss.json') @@ -29,6 +40,9 @@ let browser, page const blockBossNotNewChat = new Set() export async function mainLoop (hooks) { + if (!puppeteer) { + await initPuppeteer() + } try { browser = await puppeteer.launch({ headless: false,