From cdd71d7ab4f890959742525ada5b022c9ca55134 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Sun, 4 Dec 2022 04:33:17 -0600 Subject: [PATCH] feat: garbage collection chromium browser on close() --- src/chatgpt-api.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/chatgpt-api.ts b/src/chatgpt-api.ts index 0f81c41a..bf1933e3 100644 --- a/src/chatgpt-api.ts +++ b/src/chatgpt-api.ts @@ -48,6 +48,10 @@ export class ChatGPTAPI { async init(opts: { auth?: 'blocking' | 'eager' } = {}) { const { auth = 'eager' } = opts + if (this._browser) { + await this.close() + } + this._browser = await chromium.launchPersistentContext(this._userDataDir, { headless: this._headless }) @@ -184,7 +188,9 @@ export class ChatGPTAPI { } async close() { - return await this._browser.close() + await this._browser.close() + this._page = null + this._browser = null } protected async _getInputBox(): Promise {