diff --git a/tracker/tracker/src/common/interaction.ts b/tracker/tracker/src/common/interaction.ts index 311141169..27bd4e73a 100644 --- a/tracker/tracker/src/common/interaction.ts +++ b/tracker/tracker/src/common/interaction.ts @@ -26,6 +26,7 @@ export type ToWorkerData = | Auth | Array | { type: 'compressed'; batch: Uint8Array } + | { type: 'uncompressed'; batch: Uint8Array } type Failure = { type: 'failure' diff --git a/tracker/tracker/src/main/app/index.ts b/tracker/tracker/src/main/app/index.ts index 0b7ccc43c..62373bc23 100644 --- a/tracker/tracker/src/main/app/index.ts +++ b/tracker/tracker/src/main/app/index.ts @@ -110,6 +110,7 @@ export default class App { private activityState: ActivityState = ActivityState.NotActive private readonly version = 'TRACKER_VERSION' // TODO: version compatability check inside each plugin. private readonly worker?: TypedWorker + constructor(projectKey: string, sessionToken: string | undefined, options: Partial) { // if (options.onStart !== undefined) { // deprecationWarn("'onStart' option", "tracker.start().then(/* handle session info */)") @@ -179,10 +180,17 @@ export default class App { this.stop(false) this._debug('worker_failed', data.reason) } else if (data.type === 'compress') { - gzip(data.batch, (err, result) => { - if (err) console.error(err) - this.worker?.postMessage({ type: 'compressed', batch: result }) - }) + const batch = data.batch + const batchSize = batch.byteLength + console.log(batchSize) + if (batchSize > 1000 * 10) { + gzip(data.batch, { mtime: 0 }, (err, result) => { + if (err) console.error(err) + this.worker?.postMessage({ type: 'compressed', batch: result }) + }) + } else { + this.worker?.postMessage({ type: 'uncompressed', batch: batch }) + } } } const alertWorker = () => { diff --git a/tracker/tracker/src/webworker/QueueSender.ts b/tracker/tracker/src/webworker/QueueSender.ts index 839b51121..c80fc2251 100644 --- a/tracker/tracker/src/webworker/QueueSender.ts +++ b/tracker/tracker/src/webworker/QueueSender.ts @@ -56,7 +56,7 @@ export default class QueueSender { } // would be nice to use Beacon API, but it is not available in WebWorker - private sendBatch(batch: Uint8Array): void { + private sendBatch(batch: Uint8Array, isCompressed?: boolean): void { this.busy = true // @ts-ignore @@ -66,7 +66,7 @@ export default class QueueSender { headers: { Authorization: `Bearer ${this.token as string}`, //"Content-Type": "", - 'Content-Encoding': 'gzip', + // 'Content-Encoding': isCompressed ? 'gzip' : undefined, }, keepalive: batch.length < KEEPALIVE_SIZE_LIMIT, }) @@ -92,6 +92,10 @@ export default class QueueSender { } sendCompressed(batch: Uint8Array) { + this.sendBatch(batch, true) + } + + sendUncompressed(batch: Uint8Array) { this.sendBatch(batch) } diff --git a/tracker/tracker/src/webworker/index.ts b/tracker/tracker/src/webworker/index.ts index 776139061..bad1d641b 100644 --- a/tracker/tracker/src/webworker/index.ts +++ b/tracker/tracker/src/webworker/index.ts @@ -134,6 +134,9 @@ self.onmessage = ({ data }: any): any => { if (data.type === 'compressed') { sender?.sendCompressed(data.batch) } + if (data.type === 'uncompressed') { + sender?.sendUncompressed(data.batch) + } if (data.type === 'auth') { if (!sender) {