Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Chatgpt Puppeteer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Chatgpt Puppeteer
Commits
31a8206f
Commit
31a8206f
authored
Dec 18, 2022
by
Joel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add proxy support
parent
c331c736
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13881 additions
and
5 deletions
+13881
-5
.gitignore
.gitignore
+1
-0
package-lock.json
package-lock.json
+13840
-0
src/chatgpt-api-browser.ts
src/chatgpt-api-browser.ts
+9
-2
src/openai-auth.ts
src/openai-auth.ts
+31
-3
No files found.
.gitignore
View file @
31a8206f
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
*.swp
*.swp
.idea
# dependencies
# dependencies
/node_modules
/node_modules
...
...
package-lock.json
0 → 100644
View file @
31a8206f
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/chatgpt-api-browser.ts
View file @
31a8206f
...
@@ -29,6 +29,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
...
@@ -29,6 +29,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
protected
_executablePath
:
string
protected
_executablePath
:
string
protected
_browser
:
Browser
protected
_browser
:
Browser
protected
_page
:
Page
protected
_page
:
Page
protected
_proxyServer
:
string
/**
/**
* Creates a new client for automating the ChatGPT webapp.
* Creates a new client for automating the ChatGPT webapp.
...
@@ -54,6 +55,9 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
...
@@ -54,6 +55,9 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
/** @defaultValue `undefined` **/
/** @defaultValue `undefined` **/
executablePath
?:
string
executablePath
?:
string
/** @defaultValue `undefined` **/
proxyServer
?:
string
})
{
})
{
super
()
super
()
...
@@ -65,7 +69,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
...
@@ -65,7 +69,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
isGoogleLogin
=
false
,
isGoogleLogin
=
false
,
minimize
=
true
,
minimize
=
true
,
captchaToken
,
captchaToken
,
executablePath
executablePath
,
proxyServer
}
=
opts
}
=
opts
this
.
_email
=
email
this
.
_email
=
email
...
@@ -77,6 +82,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
...
@@ -77,6 +82,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
this
.
_minimize
=
!!
minimize
this
.
_minimize
=
!!
minimize
this
.
_captchaToken
=
captchaToken
this
.
_captchaToken
=
captchaToken
this
.
_executablePath
=
executablePath
this
.
_executablePath
=
executablePath
this
.
_proxyServer
=
proxyServer
if
(
!
this
.
_email
)
{
if
(
!
this
.
_email
)
{
const
error
=
new
types
.
ChatGPTError
(
'
ChatGPT invalid email
'
)
const
error
=
new
types
.
ChatGPTError
(
'
ChatGPT invalid email
'
)
...
@@ -99,7 +105,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
...
@@ -99,7 +105,8 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
try
{
try
{
this
.
_browser
=
await
getBrowser
({
this
.
_browser
=
await
getBrowser
({
captchaToken
:
this
.
_captchaToken
,
captchaToken
:
this
.
_captchaToken
,
executablePath
:
this
.
_executablePath
executablePath
:
this
.
_executablePath
,
proxyServer
:
this
.
_proxyServer
})
})
this
.
_page
=
this
.
_page
=
(
await
this
.
_browser
.
pages
())[
0
]
||
(
await
this
.
_browser
.
newPage
())
(
await
this
.
_browser
.
pages
())[
0
]
||
(
await
this
.
_browser
.
newPage
())
...
...
src/openai-auth.ts
View file @
31a8206f
...
@@ -55,7 +55,8 @@ export async function getOpenAIAuth({
...
@@ -55,7 +55,8 @@ export async function getOpenAIAuth({
isGoogleLogin
=
false
,
isGoogleLogin
=
false
,
captchaToken
=
process
.
env
.
CAPTCHA_TOKEN
,
captchaToken
=
process
.
env
.
CAPTCHA_TOKEN
,
nopechaKey
=
process
.
env
.
NOPECHA_KEY
,
nopechaKey
=
process
.
env
.
NOPECHA_KEY
,
executablePath
executablePath
,
proxyServer
=
process
.
env
.
PROXY_SERVER
,
}:
{
}:
{
email
?:
string
email
?:
string
password
?:
string
password
?:
string
...
@@ -65,14 +66,15 @@ export async function getOpenAIAuth({
...
@@ -65,14 +66,15 @@ export async function getOpenAIAuth({
isGoogleLogin
?:
boolean
isGoogleLogin
?:
boolean
captchaToken
?:
string
captchaToken
?:
string
nopechaKey
?:
string
nopechaKey
?:
string
executablePath
?:
string
executablePath
?:
string
,
proxyServer
?:
string
}):
Promise
<
OpenAIAuth
>
{
}):
Promise
<
OpenAIAuth
>
{
const
origBrowser
=
browser
const
origBrowser
=
browser
const
origPage
=
page
const
origPage
=
page
try
{
try
{
if
(
!
browser
)
{
if
(
!
browser
)
{
browser
=
await
getBrowser
({
captchaToken
,
nopechaKey
,
executablePath
})
browser
=
await
getBrowser
({
captchaToken
,
nopechaKey
,
executablePath
,
proxyServer
})
}
}
const
userAgent
=
await
browser
.
userAgent
()
const
userAgent
=
await
browser
.
userAgent
()
...
@@ -216,12 +218,14 @@ export async function getBrowser(
...
@@ -216,12 +218,14 @@ export async function getBrowser(
opts
:
PuppeteerLaunchOptions
&
{
opts
:
PuppeteerLaunchOptions
&
{
captchaToken
?:
string
captchaToken
?:
string
nopechaKey
?:
string
nopechaKey
?:
string
proxyServer
?:
string
}
=
{}
}
=
{}
)
{
)
{
const
{
const
{
captchaToken
=
process
.
env
.
CAPTCHA_TOKEN
,
captchaToken
=
process
.
env
.
CAPTCHA_TOKEN
,
nopechaKey
=
process
.
env
.
NOPECHA_KEY
,
nopechaKey
=
process
.
env
.
NOPECHA_KEY
,
executablePath
=
defaultChromeExecutablePath
(),
executablePath
=
defaultChromeExecutablePath
(),
proxyServer
=
process
.
env
.
PROXY_SERVER
,
...
launchOptions
...
launchOptions
}
=
opts
}
=
opts
...
@@ -274,6 +278,10 @@ export async function getBrowser(
...
@@ -274,6 +278,10 @@ export async function getBrowser(
hasNopechaExtension
=
true
hasNopechaExtension
=
true
}
}
if
(
proxyServer
)
{
puppeteerArgs
.
push
(
`--proxy-server=
${
proxyServer
}
`
)
}
const
browser
=
await
puppeteer
.
launch
({
const
browser
=
await
puppeteer
.
launch
({
headless
:
false
,
headless
:
false
,
// https://peter.sh/experiments/chromium-command-line-switches/
// https://peter.sh/experiments/chromium-command-line-switches/
...
@@ -288,6 +296,26 @@ export async function getBrowser(
...
@@ -288,6 +296,26 @@ export async function getBrowser(
...
launchOptions
...
launchOptions
})
})
if
(
process
.
env
.
PROXY_VALIDATE_IP
)
{
const
page
=
(
await
browser
.
pages
())[
0
]
||
(
await
browser
.
newPage
())
// send a fetch request to https://ifconfig.co using page.evaluate() and verify the IP matches
let
ip
;
try
{
({
ip
}
=
await
page
.
evaluate
(()
=>
{
return
fetch
(
'
https://ifconfig.co
'
,
{
headers
:
{
'
Accept
'
:
'
application/json
'
}
}).
then
((
res
)
=>
res
.
json
())
}));
}
catch
(
err
)
{
throw
new
Error
(
`Proxy IP validation failed:
${
err
.
message
}
`
)
}
if
(
ip
!==
process
.
env
.
PROXY_VALIDATE_IP
)
{
throw
new
Error
(
`Proxy IP mismatch:
${
ip
}
!==
${
process
.
env
.
PROXY_VALIDATE_IP
}
`
)
}
}
// TOdO: this is a really hackity hack way of setting the API key...
// TOdO: this is a really hackity hack way of setting the API key...
if
(
hasNopechaExtension
)
{
if
(
hasNopechaExtension
)
{
const
page
=
(
await
browser
.
pages
())[
0
]
||
(
await
browser
.
newPage
())
const
page
=
(
await
browser
.
pages
())[
0
]
||
(
await
browser
.
newPage
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment