Sync update: 2026-05-18 15:57:09
This commit is contained in:
@@ -134,7 +134,10 @@ function initWhatsApp() {
|
|||||||
'--single-process',
|
'--single-process',
|
||||||
'--disable-gpu',
|
'--disable-gpu',
|
||||||
'--disable-web-security',
|
'--disable-web-security',
|
||||||
'--disable-features=IsolateOrigins,site-per-process'
|
'--disable-features=IsolateOrigins,site-per-process',
|
||||||
|
'--disable-background-timer-throttling',
|
||||||
|
'--disable-backgrounding-occluded-windows',
|
||||||
|
'--disable-renderer-backgrounding'
|
||||||
],
|
],
|
||||||
// Realistic modern desktop user agent to bypass anti-bot detections (detaching frame errors)
|
// Realistic modern desktop user agent to bypass anti-bot detections (detaching frame errors)
|
||||||
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'
|
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'
|
||||||
@@ -290,6 +293,9 @@ async function handleMessage(ws, raw) {
|
|||||||
return respond({ type: 'error', message: 'WhatsApp is not ready' });
|
return respond({ type: 'error', message: 'WhatsApp is not ready' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const startTime = Date.now();
|
||||||
|
console.log(`[WS] get_conversations fetch started...`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const fetchChats = async () => {
|
const fetchChats = async () => {
|
||||||
const chats = await waClient.getChats();
|
const chats = await waClient.getChats();
|
||||||
@@ -297,6 +303,10 @@ async function handleMessage(ws, raw) {
|
|||||||
const offset = parseInt(payload.offset) || 0;
|
const offset = parseInt(payload.offset) || 0;
|
||||||
const slice = chats.slice(offset, offset + limit);
|
const slice = chats.slice(offset, offset + limit);
|
||||||
const formatted = await Promise.all(slice.map(formatChat));
|
const formatted = await Promise.all(slice.map(formatChat));
|
||||||
|
|
||||||
|
const duration = Date.now() - startTime;
|
||||||
|
console.log(`[WS] get_conversations fetched ${formatted.length}/${chats.length} chats in ${duration}ms`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: 'conversations',
|
type: 'conversations',
|
||||||
data: formatted,
|
data: formatted,
|
||||||
@@ -305,13 +315,14 @@ async function handleMessage(ws, raw) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const timeoutPromise = new Promise((_, reject) =>
|
const timeoutPromise = new Promise((_, reject) =>
|
||||||
setTimeout(() => reject(new Error('Server request to WhatsApp timed out')), 25000)
|
setTimeout(() => reject(new Error('Server request to WhatsApp timed out')), 45000)
|
||||||
);
|
);
|
||||||
|
|
||||||
const result = await Promise.race([fetchChats(), timeoutPromise]);
|
const result = await Promise.race([fetchChats(), timeoutPromise]);
|
||||||
return respond({ ...result, requestId });
|
return respond({ ...result, requestId });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[WS] get_conversations failed or timed out:', err.message);
|
const duration = Date.now() - startTime;
|
||||||
|
console.error(`[WS] get_conversations failed or timed out after ${duration}ms:`, err.message);
|
||||||
return respond({ type: 'error', message: err.message || 'Failed to fetch conversations', requestId });
|
return respond({ type: 'error', message: err.message || 'Failed to fetch conversations', requestId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user