posthog-js
Advanced tools
Comparing version 1.147.0 to 1.148.0
import type { blockClass, eventWithTime, hooksParam, KeepIframeSrcFn, listenerHandler, maskTextClass, RecordPlugin, SamplingStrategy } from '@rrweb/types'; | ||
import type { DataURLOptions, MaskInputFn, MaskInputOptions, MaskTextFn, Mirror, SlimDOMOptions } from 'rrweb-snapshot'; | ||
import { SnapshotBuffer } from './sessionrecording'; | ||
export declare function estimateSize(sizeable: unknown): number; | ||
export declare const replacementImageURI = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJibGFjayIvPgo8cGF0aCBkPSJNOCAwSDE2TDAgMTZWOEw4IDBaIiBmaWxsPSIjMkQyRDJEIi8+CjxwYXRoIGQ9Ik0xNiA4VjE2SDhMMTYgOFoiIGZpbGw9IiMyRDJEMkQiLz4KPC9zdmc+Cg=="; | ||
@@ -51,1 +53,3 @@ export declare const FULL_SNAPSHOT_EVENT_TYPE = 2; | ||
export declare function truncateLargeConsoleLogs(_event: eventWithTime): eventWithTime; | ||
export declare const SEVEN_MEGABYTES: number; | ||
export declare function splitBuffer(buffer: SnapshotBuffer, sizeLimit?: number): SnapshotBuffer[]; |
@@ -8,2 +8,8 @@ import { PostHog } from '../../posthog-core'; | ||
export declare const SESSION_RECORDING_BATCH_KEY = "recordings"; | ||
export interface SnapshotBuffer { | ||
size: number; | ||
data: any[]; | ||
sessionId: string; | ||
windowId: string; | ||
} | ||
export declare class SessionRecording { | ||
@@ -10,0 +16,0 @@ private readonly instance; |
{ | ||
"name": "posthog-js", | ||
"version": "1.147.0", | ||
"version": "1.148.0", | ||
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/PostHog/posthog-js", |
import type { blockClass, eventWithTime, hooksParam, KeepIframeSrcFn, listenerHandler, maskTextClass, RecordPlugin, SamplingStrategy } from '@rrweb/types'; | ||
import type { DataURLOptions, MaskInputFn, MaskInputOptions, MaskTextFn, Mirror, SlimDOMOptions } from 'rrweb-snapshot'; | ||
import { SnapshotBuffer } from './sessionrecording'; | ||
export declare function estimateSize(sizeable: unknown): number; | ||
export declare const replacementImageURI = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJibGFjayIvPgo8cGF0aCBkPSJNOCAwSDE2TDAgMTZWOEw4IDBaIiBmaWxsPSIjMkQyRDJEIi8+CjxwYXRoIGQ9Ik0xNiA4VjE2SDhMMTYgOFoiIGZpbGw9IiMyRDJEMkQiLz4KPC9zdmc+Cg=="; | ||
@@ -51,1 +53,3 @@ export declare const FULL_SNAPSHOT_EVENT_TYPE = 2; | ||
export declare function truncateLargeConsoleLogs(_event: eventWithTime): eventWithTime; | ||
export declare const SEVEN_MEGABYTES: number; | ||
export declare function splitBuffer(buffer: SnapshotBuffer, sizeLimit?: number): SnapshotBuffer[]; |
@@ -13,2 +13,27 @@ var __values = (this && this.__values) || function(o) { | ||
import { isObject } from '../../utils/type-utils'; | ||
// taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#circular_references | ||
function circularReferenceReplacer() { | ||
var ancestors = []; | ||
return function (_key, value) { | ||
if (isObject(value)) { | ||
// `this` is the object that value is contained in, | ||
// i.e., its direct parent. | ||
// @ts-expect-error - TS was unhappy with `this` on the next line but the code is copied in from MDN | ||
while (ancestors.length > 0 && ancestors.at(-1) !== this) { | ||
ancestors.pop(); | ||
} | ||
if (ancestors.includes(value)) { | ||
return '[Circular]'; | ||
} | ||
ancestors.push(value); | ||
return value; | ||
} | ||
else { | ||
return value; | ||
} | ||
}; | ||
} | ||
export function estimateSize(sizeable) { | ||
return JSON.stringify(sizeable, circularReferenceReplacer()).length; | ||
} | ||
export var replacementImageURI = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBmaWxsPSJibGFjayIvPgo8cGF0aCBkPSJNOCAwSDE2TDAgMTZWOEw4IDBaIiBmaWxsPSIjMkQyRDJEIi8+CjxwYXRoIGQ9Ik0xNiA4VjE2SDhMMTYgOFoiIGZpbGw9IiMyRDJEMkQiLz4KPC9zdmc+Cg=='; | ||
@@ -97,2 +122,30 @@ export var FULL_SNAPSHOT_EVENT_TYPE = 2; | ||
} | ||
export var SEVEN_MEGABYTES = 1024 * 1024 * 7 * 0.9; // ~7mb (with some wiggle room) | ||
// recursively splits large buffers into smaller ones | ||
// uses a pretty high size limit to avoid splitting too much | ||
export function splitBuffer(buffer, sizeLimit) { | ||
if (sizeLimit === void 0) { sizeLimit = SEVEN_MEGABYTES; } | ||
if (buffer.size >= sizeLimit && buffer.data.length > 1) { | ||
var half = Math.floor(buffer.data.length / 2); | ||
var firstHalf = buffer.data.slice(0, half); | ||
var secondHalf = buffer.data.slice(half); | ||
return [ | ||
splitBuffer({ | ||
size: estimateSize(firstHalf), | ||
data: firstHalf, | ||
sessionId: buffer.sessionId, | ||
windowId: buffer.windowId, | ||
}), | ||
splitBuffer({ | ||
size: estimateSize(secondHalf), | ||
data: secondHalf, | ||
sessionId: buffer.sessionId, | ||
windowId: buffer.windowId, | ||
}), | ||
].flatMap(function (x) { return x; }); | ||
} | ||
else { | ||
return [buffer]; | ||
} | ||
} | ||
//# sourceMappingURL=sessionrecording-utils.js.map |
@@ -8,2 +8,8 @@ import { PostHog } from '../../posthog-core'; | ||
export declare const SESSION_RECORDING_BATCH_KEY = "recordings"; | ||
export interface SnapshotBuffer { | ||
size: number; | ||
data: any[]; | ||
sessionId: string; | ||
windowId: string; | ||
} | ||
export declare class SessionRecording { | ||
@@ -10,0 +16,0 @@ private readonly instance; |
@@ -49,3 +49,3 @@ var __assign = (this && this.__assign) || function () { | ||
import { CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE, SESSION_RECORDING_CANVAS_RECORDING, SESSION_RECORDING_ENABLED_SERVER_SIDE, SESSION_RECORDING_IS_SAMPLED, SESSION_RECORDING_MINIMUM_DURATION, SESSION_RECORDING_NETWORK_PAYLOAD_CAPTURE, SESSION_RECORDING_SAMPLE_RATE, } from '../../constants'; | ||
import { FULL_SNAPSHOT_EVENT_TYPE, INCREMENTAL_SNAPSHOT_EVENT_TYPE, META_EVENT_TYPE, truncateLargeConsoleLogs, } from './sessionrecording-utils'; | ||
import { estimateSize, FULL_SNAPSHOT_EVENT_TYPE, INCREMENTAL_SNAPSHOT_EVENT_TYPE, META_EVENT_TYPE, splitBuffer, truncateLargeConsoleLogs, } from './sessionrecording-utils'; | ||
import { EventType, IncrementalSource } from '@rrweb/types'; | ||
@@ -56,3 +56,3 @@ import Config from '../../config'; | ||
import { logger } from '../../utils/logger'; | ||
import { document, assignableWindow, window } from '../../utils/globals'; | ||
import { assignableWindow, document, window } from '../../utils/globals'; | ||
import { buildNetworkRequestOptions } from './config'; | ||
@@ -87,27 +87,2 @@ import { isLocalhost } from '../../utils/request-utils'; | ||
var LOGGER_PREFIX = '[SessionRecording]'; | ||
// taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value#circular_references | ||
function circularReferenceReplacer() { | ||
var ancestors = []; | ||
return function (_key, value) { | ||
if (isObject(value)) { | ||
// `this` is the object that value is contained in, | ||
// i.e., its direct parent. | ||
// @ts-expect-error - TS was unhappy with `this` on the next line but the code is copied in from MDN | ||
while (ancestors.length > 0 && ancestors.at(-1) !== this) { | ||
ancestors.pop(); | ||
} | ||
if (ancestors.includes(value)) { | ||
return '[Circular]'; | ||
} | ||
ancestors.push(value); | ||
return value; | ||
} | ||
else { | ||
return value; | ||
} | ||
}; | ||
} | ||
function estimateSize(event) { | ||
return JSON.stringify(event, circularReferenceReplacer()).length; | ||
} | ||
var SessionRecording = /** @class */ (function () { | ||
@@ -814,7 +789,10 @@ function SessionRecording(instance) { | ||
if (this.buffer.data.length > 0) { | ||
this._captureSnapshot({ | ||
$snapshot_bytes: this.buffer.size, | ||
$snapshot_data: this.buffer.data, | ||
$session_id: this.buffer.sessionId, | ||
$window_id: this.buffer.windowId, | ||
var snapshotEvents = splitBuffer(this.buffer); | ||
snapshotEvents.forEach(function (snapshotBuffer) { | ||
_this._captureSnapshot({ | ||
$snapshot_bytes: snapshotBuffer.size, | ||
$snapshot_data: snapshotBuffer.data, | ||
$session_id: snapshotBuffer.sessionId, | ||
$window_id: snapshotBuffer.windowId, | ||
}); | ||
}); | ||
@@ -821,0 +799,0 @@ } |
{ | ||
"name": "posthog-js", | ||
"version": "1.147.0", | ||
"version": "1.148.0", | ||
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/PostHog/posthog-js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7882372
25212