Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "record and replay the web",
"scripts": {
"test": "npm run bundle:browser && cross-env TS_NODE_CACHE=false TS_NODE_FILES=true mocha -r ts-node/register test/**/*.test.ts",
"test:watch": "PUPPETEER_HEADLESS=true npm run test -- --watch --watch-extensions js,ts",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can back this out if folks disagree but found it useful

aside, it doesnt recompile src/ and I couldn't figure out how to achieve that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could not get that done too...
Combine Mocha and Typescript is not as fluent as jest.

"repl": "npm run bundle:browser && cross-env TS_NODE_CACHE=false TS_NODE_FILES=true ts-node scripts/repl.ts",
"bundle:browser": "cross-env BROWSER_ONLY=true rollup --config",
"bundle": "rollup --config",
Expand Down
12 changes: 12 additions & 0 deletions src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ function record(options: recordOptions = {}): listenerHandler | undefined {
inlineStylesheet,
maskAllInputs,
);

if (!node) {
return console.warn('Failed to snapshot the document');
}

mirror.map = idNodeMap;
wrappedEmit(
wrapEvent({
Expand Down Expand Up @@ -188,6 +190,16 @@ function record(options: recordOptions = {}): listenerHandler | undefined {
},
}),
),
styleSheetRuleCb: r =>
wrappedEmit(
wrapEvent({
type: EventType.IncrementalSnapshot,
data: {
source: IncrementalSource.StyleSheetRule,
...r,
},
}),
),
blockClass,
ignoreClass,
maskAllInputs,
Expand Down
36 changes: 36 additions & 0 deletions src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
MouseInteractions,
listenerHandler,
scrollCallback,
styleSheetRuleCallback,
viewportResizeCallback,
inputValue,
inputCallback,
Expand Down Expand Up @@ -519,6 +520,31 @@ function initInputObserver(
};
}

function initStyleSheetObserver(cb: styleSheetRuleCallback): listenerHandler {
const insertRule = CSSStyleSheet.prototype.insertRule;
CSSStyleSheet.prototype.insertRule = function(rule: string, index?: number) {
cb({
id: mirror.getId(this.ownerNode as INode),
adds: [{ rule, index }],
});
return insertRule.apply(this, arguments);
};

const deleteRule = CSSStyleSheet.prototype.deleteRule;
CSSStyleSheet.prototype.deleteRule = function(index: number) {
cb({
id: mirror.getId(this.ownerNode as INode),
removes: [{ index }],
});
return deleteRule.apply(this, arguments);
};

return () => {
CSSStyleSheet.prototype.insertRule = insertRule;
CSSStyleSheet.prototype.deleteRule = deleteRule;
};
}

function initMediaInteractionObserver(
mediaInteractionCb: mediaInteractionCallback,
blockClass: blockClass,
Expand Down Expand Up @@ -548,6 +574,7 @@ function mergeHooks(o: observerParam, hooks: hooksParam) {
viewportResizeCb,
inputCb,
mediaInteractionCb,
styleSheetRuleCb,
} = o;
o.mutationCb = (...p: Arguments<mutationCallBack>) => {
if (hooks.mutation) {
Expand Down Expand Up @@ -591,6 +618,12 @@ function mergeHooks(o: observerParam, hooks: hooksParam) {
}
mediaInteractionCb(...p);
};
o.styleSheetRuleCb = (...p: Arguments<styleSheetRuleCallback>) => {
if (hooks.styleSheetRule) {
hooks.styleSheetRule(...p);
}
styleSheetRuleCb(...p);
};
}

export default function initObservers(
Expand Down Expand Up @@ -621,6 +654,8 @@ export default function initObservers(
o.mediaInteractionCb,
o.blockClass,
);
const styleSheetObserver = initStyleSheetObserver(o.styleSheetRuleCb);

return () => {
mutationObserver.disconnect();
mousemoveHandler();
Expand All @@ -629,5 +664,6 @@ export default function initObservers(
viewportResizeHandler();
inputHandler();
mediaInteractionHandler();
styleSheetObserver();
};
}
29 changes: 28 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export type customEvent<T = unknown> = {
};
};

export type styleSheetEvent = {};

export enum IncrementalSource {
Mutation,
MouseMove,
Expand All @@ -61,6 +63,7 @@ export enum IncrementalSource {
Input,
TouchMove,
MediaInteraction,
StyleSheetRule,
}

export type mutationData = {
Expand Down Expand Up @@ -93,14 +96,19 @@ export type mediaInteractionData = {
source: IncrementalSource.MediaInteraction;
} & mediaInteractionParam;

export type styleSheetRuleData = {
source: IncrementalSource.StyleSheetRule;
} & styleSheetRuleParam;

export type incrementalData =
| mutationData
| mousemoveData
| mouseInteractionData
| scrollData
| viewportResizeData
| inputData
| mediaInteractionData;
| mediaInteractionData
| styleSheetRuleData;

export type event =
| domContentLoadedEvent
Expand Down Expand Up @@ -141,6 +149,7 @@ export type observerParam = {
ignoreClass: string;
maskAllInputs: boolean;
inlineStylesheet: boolean;
styleSheetRuleCb: styleSheetRuleCallback;
mousemoveWait: number;
};

Expand All @@ -152,6 +161,7 @@ export type hooksParam = {
viewportResize?: viewportResizeCallback;
input?: inputCallback;
mediaInteaction?: mediaInteractionCallback;
styleSheetRule?: styleSheetRuleCallback;
};

export type textCursor = {
Expand Down Expand Up @@ -239,6 +249,23 @@ export type scrollPosition = {

export type scrollCallback = (p: scrollPosition) => void;

export type styleSheetAddRule = {
rule: string;
index?: number;
};

export type styleSheetDeleteRule = {
index: number;
};

export type styleSheetRuleParam = {
id: number;
removes?: styleSheetDeleteRule[];
adds?: styleSheetAddRule[];
};

export type styleSheetRuleCallback = (s: styleSheetRuleParam) => void;

export type viewportResizeDimention = {
width: number;
height: number;
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/integration.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ exports[`block 1`] = `
\\"attributes\\": {
\\"class\\": \\"rr-block\\",
\\"rr_width\\": \\"1904px\\",
\\"rr_height\\": \\"21px\\"
\\"rr_height\\": \\"19px\\"
},
\\"childNodes\\": [],
\\"id\\": 18
Expand Down
Loading