Skip to content

Commit a074b0c

Browse files
clins1994claude
andcommitted
Make WebSocket headers configurable with sensible defaults
- Provide default browser-like headers (required by TradingView WAF) - Allow users to override via clientOptions.headers - Update User-Agent to Windows/Chrome 131 (more common, more recent) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2b94d34 commit a074b0c

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/client.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ module.exports = class Client {
218218
* @prop {boolean} [DEBUG] Enable debug mode
219219
* @prop {'data' | 'prodata' | 'widgetdata'} [server] Server type
220220
* @prop {string} [location] Auth page location (For france: https://fr.tradingview.com/)
221+
* @prop {Object<string, string>} [headers] Custom headers for the WebSocket connection (e.g. for WAF bypass)
221222
*/
222223

223224
/**
@@ -228,14 +229,16 @@ module.exports = class Client {
228229
if (clientOptions.DEBUG) global.TW_DEBUG = clientOptions.DEBUG;
229230

230231
const server = clientOptions.server || 'data';
232+
const defaultHeaders = {
233+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
234+
'Accept-Language': 'en-US,en;q=0.9',
235+
'Cache-Control': 'no-cache',
236+
Pragma: 'no-cache',
237+
};
238+
231239
this.#ws = new WebSocket(`wss://${server}.tradingview.com/socket.io/websocket?from=chart&type=chart`, {
232240
origin: 'https://www.tradingview.com',
233-
headers: {
234-
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
235-
'Accept-Language': 'en-US,en;q=0.9',
236-
'Cache-Control': 'no-cache',
237-
Pragma: 'no-cache',
238-
},
241+
headers: { ...defaultHeaders, ...clientOptions.headers },
239242
});
240243

241244
if (clientOptions.token) {

0 commit comments

Comments
 (0)