Commit e21a690e authored by Lawrence Onah's avatar Lawrence Onah

chore: add support for userDataDir

parent b5698e3a
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
"random": "^4.1.0", "random": "^4.1.0",
"remark": "^14.0.2", "remark": "^14.0.2",
"strip-markdown": "^5.0.0", "strip-markdown": "^5.0.0",
"tempy": "^3.0.0",
"uuid": "^9.0.0" "uuid": "^9.0.0"
}, },
"devDependencies": { "devDependencies": {
......
import delay from 'delay' import delay from 'delay'
import type { Browser, HTTPRequest, HTTPResponse, Page } from 'puppeteer' import type { Browser, HTTPRequest, HTTPResponse, Page } from 'puppeteer'
import { temporaryDirectory } from 'tempy'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import * as types from './types' import * as types from './types'
...@@ -37,6 +38,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { ...@@ -37,6 +38,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
string, string,
(partialResponse: types.ChatResponse) => void (partialResponse: types.ChatResponse) => void
> >
protected _userDataDir: string
/** /**
* Creates a new client for automating the ChatGPT webapp. * Creates a new client for automating the ChatGPT webapp.
...@@ -71,6 +73,9 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { ...@@ -71,6 +73,9 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
/** @defaultValue `undefined` **/ /** @defaultValue `undefined` **/
proxyServer?: string proxyServer?: string
/** @defaultValue `random directory with email as prefix` **/
userDataDir?: string
}) { }) {
super() super()
...@@ -85,7 +90,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { ...@@ -85,7 +90,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
captchaToken, captchaToken,
nopechaKey, nopechaKey,
executablePath, executablePath,
proxyServer proxyServer,
userDataDir
} = opts } = opts
this._email = email this._email = email
...@@ -102,6 +108,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { ...@@ -102,6 +108,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
this._proxyServer = proxyServer this._proxyServer = proxyServer
this._isRefreshing = false this._isRefreshing = false
this._messageOnProgressHandlers = {} this._messageOnProgressHandlers = {}
this._userDataDir =
userDataDir ?? temporaryDirectory({ prefix: this._email })
if (!this._email) { if (!this._email) {
const error = new types.ChatGPTError('ChatGPT invalid email') const error = new types.ChatGPTError('ChatGPT invalid email')
...@@ -127,7 +135,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI { ...@@ -127,7 +135,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
nopechaKey: this._nopechaKey, nopechaKey: this._nopechaKey,
executablePath: this._executablePath, executablePath: this._executablePath,
proxyServer: this._proxyServer, proxyServer: this._proxyServer,
minimize: this._minimize minimize: this._minimize,
userDataDir: this._userDataDir
}) })
this._page = await getPage(this._browser, { this._page = await getPage(this._browser, {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment