chore: add support for userDataDir

pull/271/head
Lawrence Onah 2023-01-19 14:31:08 +01:00
rodzic b5698e3ae2
commit e21a690e9e
2 zmienionych plików z 12 dodań i 2 usunięć

Wyświetl plik

@ -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": {

Wyświetl plik

@ -1,5 +1,6 @@
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 {
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 {
/** @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 {
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 {
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 {
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, {