From 09b77ee92b93e10f4a4a79a69619f5976db9d098 Mon Sep 17 00:00:00 2001 From: josc146 Date: Wed, 5 Apr 2023 17:23:11 +0800 Subject: [PATCH] chore: send complete cookie (#25, #112, #127, #150) --- src/background/apis/chatgpt-web.mjs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/background/apis/chatgpt-web.mjs b/src/background/apis/chatgpt-web.mjs index 79e0126..67e6b5c 100644 --- a/src/background/apis/chatgpt-web.mjs +++ b/src/background/apis/chatgpt-web.mjs @@ -4,6 +4,7 @@ import { fetchSSE } from '../../utils/fetch-sse' import { isEmpty } from 'lodash-es' import { chatgptWebModelKeys, getUserConfig, Models } from '../../config/index.mjs' import { pushRecord, setAbortController } from './shared.mjs' +import Browser from 'webextension-polyfill' async function request(token, method, path, data) { const apiUrl = (await getUserConfig()).customChatGptWebApiUrl @@ -67,6 +68,12 @@ export async function generateAnswersWithChatgptWebApi(port, question, session, models && models.includes(selectedModel) ? selectedModel : Models[chatgptWebModelKeys[0]].value console.debug('usedModel', usedModel) + const cookie = (await Browser.cookies.getAll({ url: 'https://chat.openai.com/' })) + .map((cookie) => { + return `${cookie.name}=${cookie.value}` + }) + .join('; ') + let answer = '' await fetchSSE(`${config.customChatGptWebApiUrl}${config.customChatGptWebApiPath}`, { method: 'POST', @@ -74,6 +81,7 @@ export async function generateAnswersWithChatgptWebApi(port, question, session, headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}`, + Cookie: cookie, }, body: JSON.stringify({ action: 'next',