From 51496ae5e225127e5d0bd92f2b7ea0c058b98dd1 Mon Sep 17 00:00:00 2001 From: Aspyryan <52763578+Aspyryan@users.noreply.github.com> Date: Mon, 3 Mar 2025 17:01:35 +0100 Subject: [PATCH] Running buffer slicing when browser is idle (#3050) * Fixed tracker uploadOfflineRecording * Make FlushBuffer perform slicing when browser is idle * Use map function to cast away proxy objects in flushBuffer --- tracker/tracker/src/main/app/index.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tracker/tracker/src/main/app/index.ts b/tracker/tracker/src/main/app/index.ts index 9cbbbf5d5..36c42764d 100644 --- a/tracker/tracker/src/main/app/index.ts +++ b/tracker/tracker/src/main/app/index.ts @@ -1635,7 +1635,7 @@ export default class App { } flushBuffer = async (buffer: Message[]) => { - return new Promise((res) => { + return new Promise((res, reject) => { if (buffer.length === 0) { res(null); return; @@ -1648,9 +1648,19 @@ export default class App { endIndex++; } - const messagesBatch = buffer.splice(0, endIndex); - this.postToWorker(messagesBatch); - res(null); + requestIdleCb(() => { + try { + const messagesBatch = buffer.splice(0, endIndex); + + // Cast out the proxy object to a regular array. + this.postToWorker(messagesBatch.map(x => [...x])); + + res(null); + } catch (e) { + this._debug('flushBuffer', e); + reject(e); + } + }) }) }