Skip to content

Commit 7af7895

Browse files
fix(bing): support setting entire cookie string, fixes #79
1 parent 2a8b74b commit 7af7895

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ npm i @waylaidwanderer/chatgpt-api
128128
import { BingAIClient } from '@waylaidwanderer/chatgpt-api';
129129

130130
const bingAIClient = new BingAIClient({
131-
userToken: '', // "_U" cookie from bing.com
131+
// "_U" cookie from bing.com
132+
userToken: '',
133+
// If the above doesn't work, provide all your cookies as a string instead
134+
cookies: '',
132135
debug: false,
133136
});
134137

@@ -243,6 +246,8 @@ module.exports = {
243246
bingAiClient: {
244247
// The "_U" cookie value from bing.com
245248
userToken: '',
249+
// If the above doesn't work, provide all your cookies as a string instead
250+
cookies: '',
246251
// (Optional) Set to true to enable `console.debug()` logging
247252
debug: false,
248253
},

demos/use-bing-client.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { BingAIClient } from '../index.js';
22

33
const bingAIClient = new BingAIClient({
4-
userToken: '', // "_U" cookie from bing.com
4+
// "_U" cookie from bing.com
5+
userToken: '',
6+
// If the above doesn't work, provide all your cookies as a string instead
7+
cookies: '',
58
debug: false,
69
});
710

settings.example.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export default {
2727
bingAiClient: {
2828
// The "_U" cookie value from bing.com
2929
userToken: '',
30+
// If the above doesn't work, provide all your cookies as a string instead
31+
cookies: '',
3032
// (Optional) Set to true to enable `console.debug()` logging
3133
debug: false,
3234
},

src/BingAIClient.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import WebSocket from 'ws';
44

55
export default class BingAIClient {
66
constructor(opts) {
7-
this.userToken = opts.userToken;
7+
this.opts = opts;
88
this.debug = opts.debug;
99
}
1010

@@ -28,7 +28,7 @@ export default class BingAIClient {
2828
"sec-fetch-site": "same-origin",
2929
"x-ms-client-request-id": crypto.randomUUID(),
3030
"x-ms-useragent": "azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.0 OS/Win32",
31-
"cookie": `_U=${this.userToken}`,
31+
"cookie": this.opts.cookies || `_U=${this.opts.userToken}`,
3232
"Referer": "https://www.bing.com/search?q=Bing+AI&showconv=1&FORM=hpcodx",
3333
"Referrer-Policy": "origin-when-cross-origin"
3434
},

0 commit comments

Comments
 (0)