record canvas mutations (#296)
* record canvas mutations close #60, #261 This patch implements the canvas mutation observer. It consists of both the record and the replay side changes. In the record side, we add a `recordCanvas` flag to indicate whether to record canvas elements and the flag defaults to false. Different from our other observers, the canvas observer was disabled by default. Because some applications with heavy canvas usage may emit a lot of data as canvas changed, especially the scenarios that use a lot of `drawImage` API. So the behavior should be audited by users and only record canvas when the flag was set to true. In the replay side, we add a `UNSAFE_replayCanvas` flag to indicate whether to replay canvas mutations. Similar to the `recordCanvas` flag, `UNSAFE_replayCanvas` defaults to false. But unlike the record canvas implementation is stable and safe, the replay canvas implementation is UNSAFE. It's unsafe because we need to add `allow-scripts` to the replay sandbox, which may cause some unexpected script execution. Currently, users should be aware of this implementation detail and enable this feature carefully. * update canvas integration test
This commit is contained in:
22
src/types.ts
22
src/types.ts
@@ -70,6 +70,7 @@ export enum IncrementalSource {
|
||||
TouchMove,
|
||||
MediaInteraction,
|
||||
StyleSheetRule,
|
||||
CanvasMutation,
|
||||
}
|
||||
|
||||
export type mutationData = {
|
||||
@@ -106,6 +107,10 @@ export type styleSheetRuleData = {
|
||||
source: IncrementalSource.StyleSheetRule;
|
||||
} & styleSheetRuleParam;
|
||||
|
||||
export type canvasMutationData = {
|
||||
source: IncrementalSource.CanvasMutation;
|
||||
} & canvasMutationParam;
|
||||
|
||||
export type incrementalData =
|
||||
| mutationData
|
||||
| mousemoveData
|
||||
@@ -114,7 +119,8 @@ export type incrementalData =
|
||||
| viewportResizeData
|
||||
| inputData
|
||||
| mediaInteractionData
|
||||
| styleSheetRuleData;
|
||||
| styleSheetRuleData
|
||||
| canvasMutationData;
|
||||
|
||||
export type event =
|
||||
| domContentLoadedEvent
|
||||
@@ -165,6 +171,7 @@ export type recordOptions<T> = {
|
||||
hooks?: hooksParam;
|
||||
packFn?: PackFn;
|
||||
sampling?: SamplingStrategy;
|
||||
recordCanvas?: boolean;
|
||||
// departed, please use sampling options
|
||||
mousemoveWait?: number;
|
||||
};
|
||||
@@ -182,7 +189,9 @@ export type observerParam = {
|
||||
maskInputOptions: MaskInputOptions;
|
||||
inlineStylesheet: boolean;
|
||||
styleSheetRuleCb: styleSheetRuleCallback;
|
||||
canvasMutationCb: canvasMutationCallback;
|
||||
sampling: SamplingStrategy;
|
||||
recordCanvas: boolean;
|
||||
};
|
||||
|
||||
export type hooksParam = {
|
||||
@@ -194,6 +203,7 @@ export type hooksParam = {
|
||||
input?: inputCallback;
|
||||
mediaInteaction?: mediaInteractionCallback;
|
||||
styleSheetRule?: styleSheetRuleCallback;
|
||||
canvasMutation?: canvasMutationCallback;
|
||||
};
|
||||
|
||||
// https://dom.spec.whatwg.org/#interface-mutationrecord
|
||||
@@ -309,6 +319,15 @@ export type styleSheetRuleParam = {
|
||||
|
||||
export type styleSheetRuleCallback = (s: styleSheetRuleParam) => void;
|
||||
|
||||
export type canvasMutationCallback = (p: canvasMutationParam) => void;
|
||||
|
||||
export type canvasMutationParam = {
|
||||
id: number;
|
||||
property: string;
|
||||
args: Array<unknown>;
|
||||
setter?: true;
|
||||
};
|
||||
|
||||
export type viewportResizeDimention = {
|
||||
width: number;
|
||||
height: number;
|
||||
@@ -362,6 +381,7 @@ export type playerConfig = {
|
||||
liveMode: boolean;
|
||||
insertStyleRules: string[];
|
||||
triggerFocus: boolean;
|
||||
UNSAFE_replayCanvas: boolean;
|
||||
unpackFn?: UnpackFn;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user