Skip to content

Commit b185337

Browse files
committed
chore: send complete cookie (#25, #112, #127, #150)
1 parent 8f274c1 commit b185337

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/background/apis/chatgpt-web.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { fetchSSE } from '../../utils/fetch-sse'
44
import { isEmpty } from 'lodash-es'
55
import { chatgptWebModelKeys, getUserConfig, Models } from '../../config/index.mjs'
66
import { pushRecord, setAbortController } from './shared.mjs'
7+
import Browser from 'webextension-polyfill'
78

89
async function request(token, method, path, data) {
910
const apiUrl = (await getUserConfig()).customChatGptWebApiUrl
@@ -67,13 +68,20 @@ export async function generateAnswersWithChatgptWebApi(port, question, session,
6768
models && models.includes(selectedModel) ? selectedModel : Models[chatgptWebModelKeys[0]].value
6869
console.debug('usedModel', usedModel)
6970

71+
const cookie = (await Browser.cookies.getAll({ url: 'https://chat.openai.com/' }))
72+
.map((cookie) => {
73+
return `${cookie.name}=${cookie.value}`
74+
})
75+
.join('; ')
76+
7077
let answer = ''
7178
await fetchSSE(`${config.customChatGptWebApiUrl}${config.customChatGptWebApiPath}`, {
7279
method: 'POST',
7380
signal: controller.signal,
7481
headers: {
7582
'Content-Type': 'application/json',
7683
Authorization: `Bearer ${accessToken}`,
84+
Cookie: cookie,
7785
},
7886
body: JSON.stringify({
7987
action: 'next',

0 commit comments

Comments
 (0)