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
8d4abc36
Commit
8d4abc36
authored
Dec 25, 2022
by
Skippy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor Cleanups to improve efficiency
parent
bfa0a90a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
28 deletions
+30
-28
src/chatgpt-api-browser.ts
src/chatgpt-api-browser.ts
+30
-28
No files found.
src/chatgpt-api-browser.ts
View file @
8d4abc36
...
@@ -336,40 +336,42 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
...
@@ -336,40 +336,42 @@ export class ChatGPTAPIBrowser extends AChatGPTAPI {
await
maximizePage
(
this
.
_page
)
await
maximizePage
(
this
.
_page
)
}
}
await
this
.
_page
.
reload
()
await
this
.
_page
.
reload
()
let
response
const
timeout
=
120000
// 2 minutes in milliseconds
// Wait for a response that includes the 'cf_clearance' cookie
// Wait for a response that includes the 'cf_clearance' cookie
const
timeout
=
30000
// 30 seconds in milliseconds
try
{
const
response
=
await
this
.
_page
.
waitForResponse
(
response
=
await
this
.
_page
.
waitForResponse
(
(
response
)
=>
{
(
response
)
=>
{
// Check if the `set-cookie` header exists in the response headers
// Check if the `set-cookie` header exists in the response headers
const
setCookie
=
response
.
headers
()[
'
set-cookie
'
]
const
setCookie
=
response
.
headers
()[
'
set-cookie
'
]
if
(
setCookie
)
{
if
(
setCookie
)
{
// Check if the `set-cookie` value contains the `cf_clearance=` string
// Check if the `set-cookie` value contains the `cf_clearance=` string
return
setCookie
.
includes
(
'
cf_clearance=
'
)
let
check
=
setCookie
.
includes
(
'
cf_clearance=
'
)
}
if
(
check
)
{
return
false
console
.
log
(
'
Found cf_clearance in set-cookie header
'
)
},
// split setCookie at cf-clearance= and get the second part, then remove the semicolon at the end
{
timeout
}
let
cf_clearance
=
setCookie
)
.
split
(
'
cf_clearance=
'
)[
1
]
.
split
(
'
;
'
)[
0
]
if
(
response
)
{
console
.
log
(
'
Cloudflare Cookie:
'
,
cf_clearance
)
console
.
log
(
'
Found cf_clearance in set-cookie header
'
)
}
}
else
{
return
check
throw
new
types
.
ChatGPTError
(
'
Failed to refresh session
'
)
}
return
false
},
{
timeout
}
)
}
catch
(
err
)
{
// useful for when cloudflare cookie is still valid, to catch TimeoutError
response
=
!!
(
await
this
.
_getInputBox
())
}
if
(
!
response
)
{
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
}
" refreshed session successfully`
)
const
pageCookies
=
await
this
.
_page
.
cookies
()
const
cookies
=
pageCookies
.
reduce
(
(
map
,
cookie
)
=>
({
...
map
,
[
cookie
.
name
]:
cookie
}),
{}
)
try
{
console
.
log
(
'
Cloudflare Cookie:
'
,
cookies
[
'
cf_clearance
'
].
value
)
}
catch
(
error
)
{
console
.
log
(
'
Cloudflare Cookie:
'
,
'
Not Found
'
)
}
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
console
.
error
(
`ChatGPT "
${
this
.
_email
}
" error refreshing session`
,
`ChatGPT "
${
this
.
_email
}
" error refreshing session`
,
...
...
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