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
4e9ce998
Commit
4e9ce998
authored
Dec 27, 2022
by
Travis Fischer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: minor fixes
parent
d57db8e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
29 deletions
+41
-29
src/chatgpt-api-browser.ts
src/chatgpt-api-browser.ts
+34
-28
src/openai-auth.ts
src/openai-auth.ts
+7
-1
No files found.
src/chatgpt-api-browser.ts
View file @
4e9ce998
...
@@ -159,7 +159,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
...
@@ -159,7 +159,7 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
this
.
_page
.
on
(
'
response
'
,
this
.
_onResponse
.
bind
(
this
))
this
.
_page
.
on
(
'
response
'
,
this
.
_onResponse
.
bind
(
this
))
// bypass cloudflare and login
// bypass cloudflare and login
var
authInfo
=
await
getOpenAIAuth
({
const
authInfo
=
await
getOpenAIAuth
({
email
:
this
.
_email
,
email
:
this
.
_email
,
password
:
this
.
_password
,
password
:
this
.
_password
,
browser
:
this
.
_browser
,
browser
:
this
.
_browser
,
...
@@ -167,8 +167,10 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
...
@@ -167,8 +167,10 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
isGoogleLogin
:
this
.
_isGoogleLogin
,
isGoogleLogin
:
this
.
_isGoogleLogin
,
isMicrosoftLogin
:
this
.
_isMicrosoftLogin
isMicrosoftLogin
:
this
.
_isMicrosoftLogin
})
})
console
.
log
(
'
Cloudflare Cookie:
'
,
authInfo
.
clearanceToken
)
console
.
log
(
'
Useragent:
'
,
authInfo
.
userAgent
)
if
(
this
.
_debug
)
{
console
.
log
(
'
chatgpt
'
,
this
.
_email
,
'
auth
'
,
authInfo
)
}
}
catch
(
err
)
{
}
catch
(
err
)
{
if
(
this
.
_browser
)
{
if
(
this
.
_browser
)
{
await
this
.
_browser
.
close
()
await
this
.
_browser
.
close
()
...
@@ -282,8 +284,10 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
...
@@ -282,8 +284,10 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
}
}
if
(
url
.
endsWith
(
'
/conversation
'
))
{
if
(
url
.
endsWith
(
'
/conversation
'
))
{
if
(
status
===
403
&&
!
this
.
_isRefreshing
)
{
if
(
status
===
403
)
{
await
this
.
refreshSession
()
console
.
log
(
`ChatGPT "
${
this
.
_email
}
" error 403...`
)
// this will be handled in the sendMessage error handler
// await this.refreshSession()
}
}
}
else
if
(
url
.
endsWith
(
'
api/auth/session
'
))
{
}
else
if
(
url
.
endsWith
(
'
api/auth/session
'
))
{
if
(
status
===
401
)
{
if
(
status
===
401
)
{
...
@@ -308,18 +312,16 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
...
@@ -308,18 +312,16 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
* Attempts to handle 401 errors by re-authenticating.
* Attempts to handle 401 errors by re-authenticating.
*/
*/
async
resetSession
()
{
async
resetSession
()
{
console
.
log
(
console
.
log
(
`ChatGPT "
${
this
.
_email
}
" resetSession...`
)
`ChatGPT "
${
this
.
_email
}
" session expired; re-authenticating...`
)
try
{
try
{
console
.
log
(
'
>>> closing session
'
,
this
.
_email
)
console
.
log
(
'
>>> closing session
'
,
this
.
_email
)
await
this
.
closeSession
()
await
this
.
closeSession
()
console
.
log
(
'
<<< closing session
'
,
this
.
_email
)
console
.
log
(
'
<<< closing session
'
,
this
.
_email
)
await
this
.
initSession
()
await
this
.
initSession
()
console
.
log
(
`ChatGPT "
${
this
.
_email
}
" re
-authenticated successfully
`
)
console
.
log
(
`ChatGPT "
${
this
.
_email
}
" re
freshSession success
`
)
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
console
.
error
(
`ChatGPT "
${
this
.
_email
}
"
error re-authenticating
`
,
`ChatGPT "
${
this
.
_email
}
"
resetSession error
`
,
err
.
toString
()
err
.
toString
()
)
)
}
}
...
@@ -329,49 +331,53 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
...
@@ -329,49 +331,53 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
* Attempts to handle 403 errors by refreshing the page.
* Attempts to handle 403 errors by refreshing the page.
*/
*/
async
refreshSession
()
{
async
refreshSession
()
{
if
(
this
.
_isRefreshing
)
{
return
}
this
.
_isRefreshing
=
true
this
.
_isRefreshing
=
true
console
.
log
(
`ChatGPT "
${
this
.
_email
}
" session expired (403); refreshing...`
)
console
.
log
(
`ChatGPT "
${
this
.
_email
}
" refreshSession...`
)
try
{
try
{
if
(
!
this
.
_minimize
)
{
if
(
!
this
.
_minimize
)
{
await
maximizePage
(
this
.
_page
)
await
maximizePage
(
this
.
_page
)
}
}
await
this
.
_page
.
reload
()
await
this
.
_page
.
reload
()
let
response
let
response
const
timeout
=
120000
// 2 minutes in milliseconds
const
timeout
=
120000
// 2 minutes in milliseconds
// Wait for a response that includes the 'cf_clearance' cookie
try
{
try
{
// Wait for a response that includes the 'cf_clearance' cookie
response
=
await
this
.
_page
.
waitForResponse
(
response
=
await
this
.
_page
.
waitForResponse
(
(
response
)
=>
{
(
response
)
=>
{
// Check if the `set-cookie` header exists in the response headers
const
cookie
=
response
.
headers
()[
'
set-cookie
'
]
const
setCookie
=
response
.
headers
()[
'
set-cookie
'
]
if
(
cookie
?.
includes
(
'
cf_clearance=
'
))
{
if
(
setCookie
)
{
const
cfClearance
=
cookie
// Check if the `set-cookie` value contains the `cf_clearance=` string
.
split
(
'
cf_clearance=
'
)?.[
1
]
let
check
=
setCookie
.
includes
(
'
cf_clearance=
'
)
?.
split
(
'
;
'
)?.[
0
]
if
(
check
)
{
// console.log('Cloudflare Cookie:', cfClearance)
console
.
log
(
'
Found cf_clearance in set-cookie header
'
)
return
true
// split setCookie at cf-clearance= and get the second part, then remove the semicolon at the end
let
cf_clearance
=
setCookie
.
split
(
'
cf_clearance=
'
)[
1
]
.
split
(
'
;
'
)[
0
]
console
.
log
(
'
Cloudflare Cookie:
'
,
cf_clearance
)
}
return
check
}
}
return
false
return
false
},
},
{
timeout
}
{
timeout
}
)
)
}
catch
(
err
)
{
}
catch
(
err
)
{
//
u
seful for when cloudflare cookie is still valid, to catch TimeoutError
//
U
seful for when cloudflare cookie is still valid, to catch TimeoutError
response
=
!!
(
await
this
.
_getInputBox
())
response
=
!!
(
await
this
.
_getInputBox
())
}
}
if
(
!
response
)
{
if
(
!
response
)
{
throw
new
types
.
ChatGPTError
(
'
Could not fetch cf_clearance cookie
'
)
throw
new
types
.
ChatGPTError
(
'
Could not fetch cf_clearance cookie
'
)
}
}
if
(
this
.
_minimize
&&
this
.
isChatPage
)
{
if
(
this
.
_minimize
&&
this
.
isChatPage
)
{
await
minimizePage
(
this
.
_page
)
await
minimizePage
(
this
.
_page
)
}
}
console
.
log
(
`ChatGPT "
${
this
.
_email
}
" refreshed session successfully`
)
console
.
log
(
`ChatGPT "
${
this
.
_email
}
" refreshSession success`
)
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
console
.
error
(
`ChatGPT "
${
this
.
_email
}
" error refreshing session`
,
`ChatGPT "
${
this
.
_email
}
" error refreshing session`
,
...
...
src/openai-auth.ts
View file @
4e9ce998
...
@@ -52,7 +52,7 @@ export async function getOpenAIAuth({
...
@@ -52,7 +52,7 @@ export async function getOpenAIAuth({
password
,
password
,
browser
,
browser
,
page
,
page
,
timeoutMs
=
2
*
60
*
1000
,
timeoutMs
=
3
*
60
*
1000
,
isGoogleLogin
=
false
,
isGoogleLogin
=
false
,
isMicrosoftLogin
=
false
,
isMicrosoftLogin
=
false
,
captchaToken
=
process
.
env
.
CAPTCHA_TOKEN
,
captchaToken
=
process
.
env
.
CAPTCHA_TOKEN
,
...
@@ -619,6 +619,12 @@ async function waitForRecaptcha(
...
@@ -619,6 +619,12 @@ async function waitForRecaptcha(
console
.
log
(
'
waiting to solve recaptcha...
'
)
console
.
log
(
'
waiting to solve recaptcha...
'
)
do
{
do
{
const
captcha
=
await
page
.
$
(
'
textarea#g-recaptcha-response
'
)
if
(
!
captcha
)
{
// the user may have gone past the page manually
break
}
const
value
=
(
await
captcha
.
evaluate
((
el
)
=>
el
.
value
))?.
trim
()
const
value
=
(
await
captcha
.
evaluate
((
el
)
=>
el
.
value
))?.
trim
()
if
(
value
?.
length
)
{
if
(
value
?.
length
)
{
// recaptcha has been solved!
// recaptcha has been solved!
...
...
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