Merge pull request #152 from alex12058/add_browser_path_opt

Closes https://github.com/transitive-bullshit/chatgpt-api/issues/140
remotes/origin/feature/api-redesign
Travis Fischer 2022-12-16 17:07:07 -06:00 zatwierdzone przez GitHub
commit bddad8b73f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 22 dodań i 5 usunięć

Wyświetl plik

@ -3,7 +3,11 @@ import type { Browser, HTTPRequest, HTTPResponse, Page } from 'puppeteer'
import { v4 as uuidv4 } from 'uuid'
import * as types from './types'
import { getBrowser, getOpenAIAuth } from './openai-auth'
import {
defaultChromeExecutablePath,
getBrowser,
getOpenAIAuth
} from './openai-auth'
import {
browserPostEventStream,
isRelevantRequest,
@ -22,6 +26,7 @@ export class ChatGPTAPIBrowser {
protected _email: string
protected _password: string
protected _browserPath: string
protected _browser: Browser
protected _page: Page
@ -46,6 +51,9 @@ export class ChatGPTAPIBrowser {
/** @defaultValue `undefined` **/
captchaToken?: string
/** @defaultValue `undefined` **/
browserPath?: string
}) {
const {
email,
@ -54,7 +62,8 @@ export class ChatGPTAPIBrowser {
debug = false,
isGoogleLogin = false,
minimize = true,
captchaToken
captchaToken,
browserPath = defaultChromeExecutablePath()
} = opts
this._email = email
@ -65,6 +74,7 @@ export class ChatGPTAPIBrowser {
this._isGoogleLogin = !!isGoogleLogin
this._minimize = !!minimize
this._captchaToken = captchaToken
this._browserPath = browserPath
}
async init() {
@ -75,7 +85,10 @@ export class ChatGPTAPIBrowser {
}
try {
this._browser = await getBrowser({ captchaToken: this._captchaToken })
this._browser = await getBrowser({
captchaToken: this._captchaToken,
executablePath: this._browserPath
})
this._page =
(await this._browser.pages())[0] || (await this._browser.newPage())

Wyświetl plik

@ -186,7 +186,11 @@ export async function getBrowser(
captchaToken?: string
} = {}
) {
const { captchaToken = process.env.CAPTCHA_TOKEN, ...launchOptions } = opts
const {
captchaToken = process.env.CAPTCHA_TOKEN,
executablePath = defaultChromeExecutablePath(),
...launchOptions
} = opts
if (captchaToken && !hasRecaptchaPlugin) {
hasRecaptchaPlugin = true
@ -207,7 +211,7 @@ export async function getBrowser(
headless: false,
args: ['--no-sandbox', '--exclude-switches', 'enable-automation'],
ignoreHTTPSErrors: true,
executablePath: defaultChromeExecutablePath(),
executablePath,
...launchOptions
})
}