Automate NPM package releases (#1119)
This commit is contained in:
@@ -90,9 +90,9 @@ function initLogObserver(
|
||||
win: IWindow, // top window or in an iframe
|
||||
options: LogRecordOptions,
|
||||
): listenerHandler {
|
||||
const logOptions = (options
|
||||
? Object.assign({}, defaultLogOptions, options)
|
||||
: defaultLogOptions) as {
|
||||
const logOptions = (
|
||||
options ? Object.assign({}, defaultLogOptions, options) : defaultLogOptions
|
||||
) as {
|
||||
level: LogLevel[];
|
||||
lengthThreshold: number;
|
||||
stringifyOptions?: StringifyOptions;
|
||||
@@ -117,9 +117,9 @@ function initLogObserver(
|
||||
const errorHandler = (event: ErrorEvent) => {
|
||||
const message = event.message,
|
||||
error = event.error as Error;
|
||||
const trace: string[] = ErrorStackParser.parse(
|
||||
error,
|
||||
).map((stackFrame: StackFrame) => stackFrame.toString());
|
||||
const trace: string[] = ErrorStackParser.parse(error).map(
|
||||
(stackFrame: StackFrame) => stackFrame.toString(),
|
||||
);
|
||||
const payload = [stringify(message, logOptions.stringifyOptions)];
|
||||
cb({
|
||||
level: 'error',
|
||||
@@ -149,9 +149,9 @@ function initLogObserver(
|
||||
stringify(event.reason, logOptions.stringifyOptions),
|
||||
];
|
||||
}
|
||||
const trace: string[] = ErrorStackParser.parse(
|
||||
error,
|
||||
).map((stackFrame: StackFrame) => stackFrame.toString());
|
||||
const trace: string[] = ErrorStackParser.parse(error).map(
|
||||
(stackFrame: StackFrame) => stackFrame.toString(),
|
||||
);
|
||||
cb({
|
||||
level: 'error',
|
||||
trace,
|
||||
|
||||
@@ -123,7 +123,7 @@ export function stringify(
|
||||
if (value instanceof Event) {
|
||||
const eventResult: Record<string, unknown> = {};
|
||||
for (const eventKey in value) {
|
||||
const eventValue = ((value as unknown) as Record<string, unknown>)[
|
||||
const eventValue = (value as unknown as Record<string, unknown>)[
|
||||
eventKey
|
||||
];
|
||||
if (Array.isArray(eventValue)) {
|
||||
|
||||
@@ -59,10 +59,10 @@ class LogReplayPlugin {
|
||||
for (const level of this.config.level!) {
|
||||
if (level === 'trace') {
|
||||
replayLogger[level] = (data: LogData) => {
|
||||
const logger = ((console.log as unknown) as PatchedConsoleLog)[
|
||||
const logger = (console.log as unknown as PatchedConsoleLog)[
|
||||
ORIGINAL_ATTRIBUTE_NAME
|
||||
]
|
||||
? ((console.log as unknown) as PatchedConsoleLog)[
|
||||
? (console.log as unknown as PatchedConsoleLog)[
|
||||
ORIGINAL_ATTRIBUTE_NAME
|
||||
]
|
||||
: console.log;
|
||||
@@ -73,10 +73,10 @@ class LogReplayPlugin {
|
||||
};
|
||||
} else {
|
||||
replayLogger[level] = (data: LogData) => {
|
||||
const logger = ((console[level] as unknown) as PatchedConsoleLog)[
|
||||
const logger = (console[level] as unknown as PatchedConsoleLog)[
|
||||
ORIGINAL_ATTRIBUTE_NAME
|
||||
]
|
||||
? ((console[level] as unknown) as PatchedConsoleLog)[
|
||||
? (console[level] as unknown as PatchedConsoleLog)[
|
||||
ORIGINAL_ATTRIBUTE_NAME
|
||||
]
|
||||
: console[level];
|
||||
@@ -118,7 +118,7 @@ export const getReplayConsolePlugin: (
|
||||
event.type === EventType.IncrementalSnapshot &&
|
||||
event.data.source === (IncrementalSource.Log as IncrementalSource)
|
||||
) {
|
||||
logData = (event.data as unknown) as LogData;
|
||||
logData = event.data as unknown as LogData;
|
||||
} else if (
|
||||
event.type === EventType.Plugin &&
|
||||
event.data.plugin === PLUGIN_NAME
|
||||
|
||||
@@ -22,7 +22,7 @@ export const getReplaySequentialIdPlugin: (
|
||||
return {
|
||||
handler(event: eventWithTime) {
|
||||
if (key in event) {
|
||||
const id = ((event as unknown) as Record<string, number>)[key];
|
||||
const id = (event as unknown as Record<string, number>)[key];
|
||||
if (id !== currentId) {
|
||||
console.error(
|
||||
`[sequential-id-plugin]: expect to get an id with value "${currentId}", but got "${id}"`,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { ICrossOriginIframeMirror } from '@rrweb/types';
|
||||
export default class CrossOriginIframeMirror
|
||||
implements ICrossOriginIframeMirror {
|
||||
implements ICrossOriginIframeMirror
|
||||
{
|
||||
private iframeIdToRemoteIdMap: WeakMap<
|
||||
HTMLIFrameElement,
|
||||
Map<number, number>
|
||||
|
||||
@@ -8,16 +8,12 @@ import type { StylesheetManager } from './stylesheet-manager';
|
||||
|
||||
export class IframeManager {
|
||||
private iframes: WeakMap<HTMLIFrameElement, true> = new WeakMap();
|
||||
private crossOriginIframeMap: WeakMap<
|
||||
MessageEventSource,
|
||||
HTMLIFrameElement
|
||||
> = new WeakMap();
|
||||
private crossOriginIframeMap: WeakMap<MessageEventSource, HTMLIFrameElement> =
|
||||
new WeakMap();
|
||||
public crossOriginIframeMirror = new CrossOriginIframeMirror(genId);
|
||||
public crossOriginIframeStyleMirror: CrossOriginIframeMirror;
|
||||
public crossOriginIframeRootIdMap: WeakMap<
|
||||
HTMLIFrameElement,
|
||||
number
|
||||
> = new WeakMap();
|
||||
public crossOriginIframeRootIdMap: WeakMap<HTMLIFrameElement, number> =
|
||||
new WeakMap();
|
||||
private mirror: Mirror;
|
||||
private mutationCb: mutationCallBack;
|
||||
private wrappedEmit: (e: eventWithTime, isCheckout?: boolean) => void;
|
||||
|
||||
@@ -173,9 +173,9 @@ function record<T = eventWithTime>(
|
||||
// Disable packing events which will be emitted to parent frames.
|
||||
!passEmitsToParent
|
||||
) {
|
||||
e = (packFn(e) as unknown) as eventWithTime;
|
||||
e = packFn(e) as unknown as eventWithTime;
|
||||
}
|
||||
return (e as unknown) as T;
|
||||
return e as unknown as T;
|
||||
};
|
||||
wrappedEmit = (e: eventWithTime, isCheckout?: boolean) => {
|
||||
if (
|
||||
|
||||
@@ -180,29 +180,31 @@ export default class MutationBuffer {
|
||||
private processedNodeManager: observerParam['processedNodeManager'];
|
||||
|
||||
public init(options: MutationBufferParam) {
|
||||
([
|
||||
'mutationCb',
|
||||
'blockClass',
|
||||
'blockSelector',
|
||||
'maskTextClass',
|
||||
'maskTextSelector',
|
||||
'inlineStylesheet',
|
||||
'maskInputOptions',
|
||||
'maskTextFn',
|
||||
'maskInputFn',
|
||||
'keepIframeSrcFn',
|
||||
'recordCanvas',
|
||||
'inlineImages',
|
||||
'slimDOMOptions',
|
||||
'dataURLOptions',
|
||||
'doc',
|
||||
'mirror',
|
||||
'iframeManager',
|
||||
'stylesheetManager',
|
||||
'shadowDomManager',
|
||||
'canvasManager',
|
||||
'processedNodeManager',
|
||||
] as const).forEach((key) => {
|
||||
(
|
||||
[
|
||||
'mutationCb',
|
||||
'blockClass',
|
||||
'blockSelector',
|
||||
'maskTextClass',
|
||||
'maskTextSelector',
|
||||
'inlineStylesheet',
|
||||
'maskInputOptions',
|
||||
'maskTextFn',
|
||||
'maskInputFn',
|
||||
'keepIframeSrcFn',
|
||||
'recordCanvas',
|
||||
'inlineImages',
|
||||
'slimDOMOptions',
|
||||
'dataURLOptions',
|
||||
'doc',
|
||||
'mirror',
|
||||
'iframeManager',
|
||||
'stylesheetManager',
|
||||
'shadowDomManager',
|
||||
'canvasManager',
|
||||
'processedNodeManager',
|
||||
] as const
|
||||
).forEach((key) => {
|
||||
// just a type trick, the runtime result is correct
|
||||
this[key] = options[key] as never;
|
||||
});
|
||||
|
||||
@@ -94,19 +94,18 @@ export function initMutationObserver(
|
||||
* window.__rrMutationObserver = MutationObserver
|
||||
*/
|
||||
(window as WindowWithStoredMutationObserver).__rrMutationObserver;
|
||||
const angularZoneSymbol = (window as WindowWithAngularZone)?.Zone?.__symbol__?.(
|
||||
'MutationObserver',
|
||||
);
|
||||
const angularZoneSymbol = (
|
||||
window as WindowWithAngularZone
|
||||
)?.Zone?.__symbol__?.('MutationObserver');
|
||||
if (
|
||||
angularZoneSymbol &&
|
||||
((window as unknown) as Record<string, typeof MutationObserver>)[
|
||||
(window as unknown as Record<string, typeof MutationObserver>)[
|
||||
angularZoneSymbol
|
||||
]
|
||||
) {
|
||||
mutationObserverCtor = ((window as unknown) as Record<
|
||||
string,
|
||||
typeof MutationObserver
|
||||
>)[angularZoneSymbol];
|
||||
mutationObserverCtor = (
|
||||
window as unknown as Record<string, typeof MutationObserver>
|
||||
)[angularZoneSymbol];
|
||||
}
|
||||
const observer = new (mutationObserverCtor as new (
|
||||
callback: MutationCallback,
|
||||
@@ -423,9 +422,9 @@ function initInputObserver({
|
||||
}
|
||||
}
|
||||
const events = sampling.input === 'last' ? ['change'] : ['input', 'change'];
|
||||
const handlers: Array<
|
||||
listenerHandler | hookResetter
|
||||
> = events.map((eventName) => on(eventName, eventHandler, doc));
|
||||
const handlers: Array<listenerHandler | hookResetter> = events.map(
|
||||
(eventName) => on(eventName, eventHandler, doc),
|
||||
);
|
||||
const currentWindow = doc.defaultView;
|
||||
if (!currentWindow) {
|
||||
return () => {
|
||||
@@ -891,12 +890,8 @@ function initMediaInteractionObserver({
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const {
|
||||
currentTime,
|
||||
volume,
|
||||
muted,
|
||||
playbackRate,
|
||||
} = target as HTMLMediaElement;
|
||||
const { currentTime, volume, muted, playbackRate } =
|
||||
target as HTMLMediaElement;
|
||||
mediaInteractionCb({
|
||||
type,
|
||||
id: mirror.getId(target as Node),
|
||||
@@ -931,7 +926,7 @@ function initFontObserver({ fontCb, doc }: observerParam): listenerHandler {
|
||||
const fontMap = new WeakMap<FontFace, fontParam>();
|
||||
|
||||
const originalFontFace = win.FontFace;
|
||||
win.FontFace = (function FontFace(
|
||||
win.FontFace = function FontFace(
|
||||
family: string,
|
||||
source: string | ArrayBufferLike,
|
||||
descriptors?: FontFaceDescriptors,
|
||||
@@ -947,7 +942,7 @@ function initFontObserver({ fontCb, doc }: observerParam): listenerHandler {
|
||||
: JSON.stringify(Array.from(new Uint8Array(source))),
|
||||
});
|
||||
return fontFace;
|
||||
} as unknown) as typeof FontFace;
|
||||
} as unknown as typeof FontFace;
|
||||
|
||||
const restoreHandler = patch(
|
||||
doc.fonts,
|
||||
|
||||
@@ -116,7 +116,8 @@ export class CanvasManager {
|
||||
blockSelector,
|
||||
);
|
||||
const snapshotInProgressMap: Map<number, boolean> = new Map();
|
||||
const worker = new ImageBitmapDataURLWorker() as ImageBitmapDataURLRequestWorker;
|
||||
const worker =
|
||||
new ImageBitmapDataURLWorker() as ImageBitmapDataURLRequestWorker;
|
||||
worker.onmessage = (e) => {
|
||||
const { id } = e.data;
|
||||
snapshotInProgressMap.set(id, false);
|
||||
|
||||
@@ -81,7 +81,7 @@ export class ShadowDomManager {
|
||||
scrollCb: this.scrollCb,
|
||||
// https://gist.github.com/praveenpuglia/0832da687ed5a5d7a0907046c9ef1813
|
||||
// scroll is not allowed to pass the boundary, so we need to listen the shadow document
|
||||
doc: (shadowRoot as unknown) as Document,
|
||||
doc: shadowRoot as unknown as Document,
|
||||
mirror: this.mirror,
|
||||
});
|
||||
// Defer this to avoid adoptedStyleSheet events being created before the full snapshot is created or attachShadow action is recorded.
|
||||
@@ -113,9 +113,11 @@ export class ShadowDomManager {
|
||||
const manager = this;
|
||||
this.restorePatches.push(
|
||||
patch(
|
||||
(iframeElement.contentWindow as Window & {
|
||||
HTMLElement: { prototype: HTMLElement };
|
||||
}).HTMLElement.prototype,
|
||||
(
|
||||
iframeElement.contentWindow as Window & {
|
||||
HTMLElement: { prototype: HTMLElement };
|
||||
}
|
||||
).HTMLElement.prototype,
|
||||
'attachShadow',
|
||||
function (original: (init: ShadowRootInit) => ShadowRoot) {
|
||||
return function (this: HTMLElement, option: ShadowRootInit) {
|
||||
|
||||
@@ -20,7 +20,7 @@ export default async function canvasMutation({
|
||||
|
||||
if (mutation.setter) {
|
||||
// skip some read-only type checks
|
||||
((ctx as unknown) as Record<string, unknown>)[mutation.property] =
|
||||
(ctx as unknown as Record<string, unknown>)[mutation.property] =
|
||||
mutation.args[0];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -434,9 +434,10 @@ export class Replayer {
|
||||
|
||||
public getMetaData(): playerMetaData {
|
||||
const firstEvent = this.service.state.context.events[0];
|
||||
const lastEvent = this.service.state.context.events[
|
||||
this.service.state.context.events.length - 1
|
||||
];
|
||||
const lastEvent =
|
||||
this.service.state.context.events[
|
||||
this.service.state.context.events.length - 1
|
||||
];
|
||||
return {
|
||||
startTime: firstEvent.timestamp,
|
||||
endTime: lastEvent.timestamp,
|
||||
@@ -855,7 +856,7 @@ export class Replayer {
|
||||
const collected: AppendedIframe[] = [];
|
||||
const afterAppend = (builtNode: Node, id: number) => {
|
||||
this.collectIframeAndAttachDocument(collected, builtNode);
|
||||
const sn = (mirror as TMirror).getMeta((builtNode as unknown) as TNode);
|
||||
const sn = (mirror as TMirror).getMeta(builtNode as unknown as TNode);
|
||||
if (
|
||||
sn?.type === NodeType.Element &&
|
||||
sn?.tagName.toUpperCase() === 'HTML'
|
||||
@@ -1263,9 +1264,9 @@ export class Replayer {
|
||||
if (this.usingVirtualDom) {
|
||||
if (d.styleId) this.constructedStyleMutations.push(d);
|
||||
else if (d.id)
|
||||
(this.virtualDom.mirror.getNode(
|
||||
d.id,
|
||||
) as RRStyleElement | null)?.rules.push(d);
|
||||
(
|
||||
this.virtualDom.mirror.getNode(d.id) as RRStyleElement | null
|
||||
)?.rules.push(d);
|
||||
} else this.applyStyleSheetMutation(d);
|
||||
break;
|
||||
}
|
||||
@@ -1916,10 +1917,10 @@ export class Replayer {
|
||||
styleSheet: CSSStyleSheet,
|
||||
) {
|
||||
if (data.set) {
|
||||
const rule = (getNestedRule(
|
||||
const rule = getNestedRule(
|
||||
styleSheet.rules,
|
||||
data.index,
|
||||
) as unknown) as CSSStyleRule;
|
||||
) as unknown as CSSStyleRule;
|
||||
rule.style.setProperty(
|
||||
data.set.property,
|
||||
data.set.value,
|
||||
@@ -1928,10 +1929,10 @@ export class Replayer {
|
||||
}
|
||||
|
||||
if (data.remove) {
|
||||
const rule = (getNestedRule(
|
||||
const rule = getNestedRule(
|
||||
styleSheet.rules,
|
||||
data.index,
|
||||
) as unknown) as CSSStyleRule;
|
||||
) as unknown as CSSStyleRule;
|
||||
rule.style.removeProperty(data.remove.property);
|
||||
}
|
||||
}
|
||||
@@ -1977,7 +1978,8 @@ export class Replayer {
|
||||
.filter((style) => style !== null) as CSSStyleSheet[];
|
||||
if (hasShadowRoot(targetHost))
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
(targetHost as HTMLElement).shadowRoot!.adoptedStyleSheets = stylesToAdopt;
|
||||
(targetHost as HTMLElement).shadowRoot!.adoptedStyleSheets =
|
||||
stylesToAdopt;
|
||||
else if (targetHost.nodeName === '#document')
|
||||
(targetHost as Document).adoptedStyleSheets = stylesToAdopt;
|
||||
|
||||
|
||||
@@ -209,4 +209,5 @@ export type CrossOriginIframeMessageEventContent<T = eventWithTime> = {
|
||||
origin: string;
|
||||
isCheckout?: boolean;
|
||||
};
|
||||
export type CrossOriginIframeMessageEvent = MessageEvent<CrossOriginIframeMessageEventContent>;
|
||||
export type CrossOriginIframeMessageEvent =
|
||||
MessageEvent<CrossOriginIframeMessageEventContent>;
|
||||
|
||||
@@ -281,14 +281,14 @@ export function isTouchEvent(
|
||||
export function polyfill(win = window) {
|
||||
if ('NodeList' in win && !win.NodeList.prototype.forEach) {
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
win.NodeList.prototype.forEach = (Array.prototype
|
||||
.forEach as unknown) as NodeList['forEach'];
|
||||
win.NodeList.prototype.forEach = Array.prototype
|
||||
.forEach as unknown as NodeList['forEach'];
|
||||
}
|
||||
|
||||
if ('DOMTokenList' in win && !win.DOMTokenList.prototype.forEach) {
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
win.DOMTokenList.prototype.forEach = (Array.prototype
|
||||
.forEach as unknown) as DOMTokenList['forEach'];
|
||||
win.DOMTokenList.prototype.forEach = Array.prototype
|
||||
.forEach as unknown as DOMTokenList['forEach'];
|
||||
}
|
||||
|
||||
// https://github.com/Financial-Times/polyfill-service/pull/183
|
||||
@@ -433,7 +433,7 @@ export function getBaseDimension(
|
||||
export function hasShadowRoot<T extends Node | RRNode>(
|
||||
n: T,
|
||||
): n is T & { shadowRoot: ShadowRoot } {
|
||||
return Boolean(((n as unknown) as Element)?.shadowRoot);
|
||||
return Boolean((n as unknown as Element)?.shadowRoot);
|
||||
}
|
||||
|
||||
export function getNestedRule(
|
||||
|
||||
@@ -147,8 +147,7 @@ const events: eventWithTime[] = [
|
||||
id: 101,
|
||||
adds: [
|
||||
{
|
||||
rule:
|
||||
'.css-added-at-500-overwritten-at-3000 {border: 1px solid blue;}',
|
||||
rule: '.css-added-at-500-overwritten-at-3000 {border: 1px solid blue;}',
|
||||
index: 1,
|
||||
},
|
||||
],
|
||||
@@ -163,8 +162,7 @@ const events: eventWithTime[] = [
|
||||
id: 105,
|
||||
adds: [
|
||||
{
|
||||
rule:
|
||||
'.css-added-at-1000-deleted-at-2500{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;min-width:60rem;min-height:100vh;color:blue;}',
|
||||
rule: '.css-added-at-1000-deleted-at-2500{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;min-width:60rem;min-height:100vh;color:blue;}',
|
||||
index: 2,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -502,7 +502,8 @@ describe('record integration tests', function (this: ISuite) {
|
||||
await page.goto('about:blank');
|
||||
await page.setContent(
|
||||
getHtml('log.html', {
|
||||
plugins: ('[rrwebConsoleRecord.getRecordConsolePlugin()]' as unknown) as RecordPlugin<unknown>[],
|
||||
plugins:
|
||||
'[rrwebConsoleRecord.getRecordConsolePlugin()]' as unknown as RecordPlugin<unknown>[],
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -790,8 +791,8 @@ describe('record integration tests', function (this: ISuite) {
|
||||
|
||||
await page.evaluate(() => {
|
||||
// get contentDocument of iframe five
|
||||
const contentDocument1 = document.querySelector('iframe')!
|
||||
.contentDocument!;
|
||||
const contentDocument1 =
|
||||
document.querySelector('iframe')!.contentDocument!;
|
||||
// create shadow dom #1
|
||||
contentDocument1.body.attachShadow({ mode: 'open' });
|
||||
contentDocument1.body.shadowRoot!.appendChild(
|
||||
|
||||
@@ -17,7 +17,7 @@ describe('pack', () => {
|
||||
|
||||
describe('unpack', () => {
|
||||
it('is compatible with unpacked data 1', () => {
|
||||
const result = unpack((event as unknown) as string);
|
||||
const result = unpack(event as unknown as string);
|
||||
expect(result).toEqual(event);
|
||||
});
|
||||
|
||||
|
||||
@@ -96,9 +96,9 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
it('will only have one full snapshot without checkout config', async () => {
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
record({
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
});
|
||||
let count = 30;
|
||||
@@ -120,9 +120,9 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
it('can checkout full snapshot by count', async () => {
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
record({
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
checkoutEveryNth: 10,
|
||||
});
|
||||
});
|
||||
@@ -149,9 +149,9 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
it('can checkout full snapshot by time', async () => {
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
record({
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
checkoutEveryNms: 500,
|
||||
});
|
||||
});
|
||||
@@ -182,9 +182,9 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
it('is safe to checkout during async callbacks', async () => {
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
record({
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
checkoutEveryNth: 2,
|
||||
});
|
||||
const p = document.createElement('p');
|
||||
@@ -208,9 +208,9 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
it('should record scroll position', async () => {
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
record({
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
const p = document.createElement('p');
|
||||
p.innerText = 'testtesttesttesttesttesttesttesttesttest';
|
||||
@@ -225,9 +225,9 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
it('should record selection event', async () => {
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
record({
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
const startNode = document.createElement('p');
|
||||
|
||||
@@ -266,9 +266,9 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
it('can add custom event', async () => {
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record, addCustomEvent } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record, addCustomEvent } = (window as unknown as IWindow).rrweb;
|
||||
record({
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
addCustomEvent<number>('tag1', 1);
|
||||
addCustomEvent<{ a: string }>('tag2', {
|
||||
@@ -281,10 +281,10 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
it('captures stylesheet rules', async () => {
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
|
||||
record({
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
|
||||
const styleElement = document.createElement('style');
|
||||
@@ -331,10 +331,10 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
const captureNestedStylesheetRulesTest = async () => {
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
|
||||
record({
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
|
||||
const styleElement = document.createElement('style');
|
||||
@@ -392,10 +392,10 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
it('captures style property changes', async () => {
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
|
||||
record({
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
ignoreCSSAttributes: new Set(['color']),
|
||||
});
|
||||
|
||||
@@ -428,7 +428,7 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
it('captures inserted style text nodes correctly', async () => {
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
|
||||
const styleEl = document.createElement(`style`);
|
||||
styleEl.append(document.createTextNode('div { color: red; }'));
|
||||
@@ -436,7 +436,7 @@ describe('record', function (this: ISuite) {
|
||||
document.head.appendChild(styleEl);
|
||||
|
||||
record({
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
|
||||
styleEl.append(document.createTextNode('span { color: orange; }'));
|
||||
@@ -462,11 +462,11 @@ describe('record', function (this: ISuite) {
|
||||
});
|
||||
await waitForRAF(ctx.page);
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
|
||||
record({
|
||||
inlineStylesheet: true,
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
});
|
||||
await waitForRAF(ctx.page);
|
||||
@@ -487,14 +487,15 @@ describe('record', function (this: ISuite) {
|
||||
document.adoptedStyleSheets = [sheet];
|
||||
|
||||
const iframe = document.querySelector('iframe');
|
||||
const sheet2 = new (iframe!.contentWindow! as Window &
|
||||
typeof globalThis).CSSStyleSheet();
|
||||
const sheet2 = new (
|
||||
iframe!.contentWindow! as Window & typeof globalThis
|
||||
).CSSStyleSheet();
|
||||
|
||||
// Add stylesheet to an IFrame document.
|
||||
iframe!.contentDocument!.adoptedStyleSheets = [sheet2];
|
||||
iframe!.contentDocument!.body.innerHTML = '<h1>h1 in iframe</h1>';
|
||||
|
||||
const { rrweb, emit } = (window as unknown) as IWindow;
|
||||
const { rrweb, emit } = window as unknown as IWindow;
|
||||
rrweb.record({
|
||||
emit,
|
||||
});
|
||||
@@ -568,7 +569,7 @@ describe('record', function (this: ISuite) {
|
||||
sheet2.replaceSync!('div {font-size: large;}');
|
||||
shadowHost.shadowRoot!.adoptedStyleSheets = [sheet2];
|
||||
|
||||
const { rrweb, emit } = (window as unknown) as IWindow;
|
||||
const { rrweb, emit } = window as unknown as IWindow;
|
||||
rrweb.record({
|
||||
emit,
|
||||
});
|
||||
@@ -602,7 +603,7 @@ describe('record', function (this: ISuite) {
|
||||
sheet.replaceSync!('h1 {color: blue;}');
|
||||
shadowHost.shadowRoot!.adoptedStyleSheets = [sheet];
|
||||
|
||||
const { rrweb, emit } = (window as unknown) as IWindow;
|
||||
const { rrweb, emit } = window as unknown as IWindow;
|
||||
rrweb.record({
|
||||
emit,
|
||||
});
|
||||
@@ -639,11 +640,11 @@ describe('record', function (this: ISuite) {
|
||||
});
|
||||
await waitForRAF(ctx.page);
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
|
||||
record({
|
||||
inlineStylesheet: true,
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
});
|
||||
await waitForRAF(ctx.page);
|
||||
@@ -683,11 +684,11 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
it('captures stylesheets that are still loading', async () => {
|
||||
ctx.page.evaluate((serverURL) => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
|
||||
record({
|
||||
inlineStylesheet: true,
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
|
||||
const link1 = document.createElement('link');
|
||||
@@ -708,11 +709,11 @@ describe('record', function (this: ISuite) {
|
||||
iframe.setAttribute('src', `/html/hello-world.html?2`);
|
||||
document.body.appendChild(iframe);
|
||||
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
|
||||
record({
|
||||
inlineStylesheet: true,
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -743,11 +744,11 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
// do not `await` the following function, otherwise `waitForResponse` _might_ not be called
|
||||
void ctx.page.evaluate((corsStylesheetURL) => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
|
||||
record({
|
||||
inlineStylesheet: true,
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
|
||||
const link1 = document.createElement('link');
|
||||
@@ -793,8 +794,9 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
// Add stylesheet to an IFrame document.
|
||||
const iframe = document.querySelector('iframe');
|
||||
const sheet3 = new (iframe!.contentWindow! as IWindow &
|
||||
typeof globalThis).CSSStyleSheet();
|
||||
const sheet3 = new (
|
||||
iframe!.contentWindow! as IWindow & typeof globalThis
|
||||
).CSSStyleSheet();
|
||||
sheet3.replaceSync!('h1 { color: blue; }');
|
||||
|
||||
iframe!.contentDocument!.adoptedStyleSheets = [sheet3];
|
||||
@@ -803,8 +805,8 @@ describe('record', function (this: ISuite) {
|
||||
ele.innerText = 'h1 in iframe';
|
||||
iframe!.contentDocument!.body.appendChild(ele);
|
||||
|
||||
((window as unknown) as IWindow).rrweb.record({
|
||||
emit: ((window.top as unknown) as IWindow).emit,
|
||||
(window as unknown as IWindow).rrweb.record({
|
||||
emit: (window.top as unknown as IWindow).emit,
|
||||
});
|
||||
|
||||
// Make incremental changes to shadow dom.
|
||||
@@ -819,8 +821,9 @@ describe('record', function (this: ISuite) {
|
||||
|
||||
document.adoptedStyleSheets = [sheet4, sheet, sheet2];
|
||||
|
||||
const sheet5 = new (iframe!.contentWindow! as IWindow &
|
||||
typeof globalThis).CSSStyleSheet();
|
||||
const sheet5 = new (
|
||||
iframe!.contentWindow! as IWindow & typeof globalThis
|
||||
).CSSStyleSheet();
|
||||
sheet5.replaceSync!('h2 { color: purple; }');
|
||||
iframe!.contentDocument!.adoptedStyleSheets = [sheet5, sheet3];
|
||||
}, 10);
|
||||
@@ -853,9 +856,9 @@ describe('record iframes', function (this: ISuite) {
|
||||
|
||||
it('captures iframe content in correct order', async () => {
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
record({
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
});
|
||||
await waitForRAF(ctx.page);
|
||||
@@ -877,10 +880,10 @@ describe('record iframes', function (this: ISuite) {
|
||||
|
||||
it('captures stylesheet mutations in iframes', async () => {
|
||||
await ctx.page.evaluate(() => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
record({
|
||||
// need to reference window.top for when we are in an iframe!
|
||||
emit: ((window.top as unknown) as IWindow).emit,
|
||||
emit: (window.top as unknown as IWindow).emit,
|
||||
});
|
||||
|
||||
const iframe = document.querySelector('iframe');
|
||||
|
||||
@@ -51,14 +51,14 @@ async function injectRecordScript(
|
||||
});
|
||||
options = options || {};
|
||||
await frame.evaluate((options) => {
|
||||
((window as unknown) as IWindow).snapshots = [];
|
||||
const { record, pack } = ((window as unknown) as IWindow).rrweb;
|
||||
(window as unknown as IWindow).snapshots = [];
|
||||
const { record, pack } = (window as unknown as IWindow).rrweb;
|
||||
const config: recordOptions<eventWithTime> = {
|
||||
recordCrossOriginIframes: true,
|
||||
recordCanvas: true,
|
||||
emit(event) {
|
||||
((window as unknown) as IWindow).snapshots.push(event);
|
||||
((window as unknown) as IWindow).emit(event);
|
||||
(window as unknown as IWindow).snapshots.push(event);
|
||||
(window as unknown as IWindow).emit(event);
|
||||
},
|
||||
};
|
||||
if (options.usePackFn) {
|
||||
@@ -148,21 +148,21 @@ describe('cross origin iframes', function (this: ISuite) {
|
||||
|
||||
const frame = await el.contentFrame();
|
||||
const events = await frame?.evaluate(
|
||||
() => ((window as unknown) as IWindow).snapshots,
|
||||
() => (window as unknown as IWindow).snapshots,
|
||||
);
|
||||
expect(events).toMatchObject([]);
|
||||
});
|
||||
|
||||
it('will emit events if it is in the top level iframe', async () => {
|
||||
const events = await ctx.page.evaluate(
|
||||
() => ((window as unknown) as IWindow).snapshots,
|
||||
() => (window as unknown as IWindow).snapshots,
|
||||
);
|
||||
expect(events.length).not.toBe(0);
|
||||
});
|
||||
|
||||
it('should emit contents of iframe', async () => {
|
||||
const events = await ctx.page.evaluate(
|
||||
() => ((window as unknown) as IWindow).snapshots,
|
||||
() => (window as unknown as IWindow).snapshots,
|
||||
);
|
||||
await waitForRAF(ctx.page);
|
||||
// two events (full snapshot + meta) from main frame, and one full snapshot from iframe
|
||||
@@ -171,7 +171,7 @@ describe('cross origin iframes', function (this: ISuite) {
|
||||
|
||||
it('should emit full snapshot event from iframe as mutation event', async () => {
|
||||
const events = await ctx.page.evaluate(
|
||||
() => ((window as unknown) as IWindow).snapshots,
|
||||
() => (window as unknown as IWindow).snapshots,
|
||||
);
|
||||
await waitForRAF(ctx.page);
|
||||
// two events from main frame, and two from iframe
|
||||
@@ -193,7 +193,7 @@ describe('cross origin iframes', function (this: ISuite) {
|
||||
|
||||
it('should use unique id for child of iframes', async () => {
|
||||
const events: eventWithTime[] = await ctx.page.evaluate(
|
||||
() => ((window as unknown) as IWindow).snapshots,
|
||||
() => (window as unknown as IWindow).snapshots,
|
||||
);
|
||||
await waitForRAF(ctx.page);
|
||||
expect(
|
||||
@@ -211,7 +211,7 @@ describe('cross origin iframes', function (this: ISuite) {
|
||||
await injectRecordScript(ctx.page.mainFrame().childFrames()[0]); // injects script into new iframe
|
||||
|
||||
const events: eventWithTime[] = await ctx.page.evaluate(
|
||||
() => ((window as unknown) as IWindow).snapshots,
|
||||
() => (window as unknown as IWindow).snapshots,
|
||||
);
|
||||
expect(
|
||||
(events[events.length - 1].data as mutationData).removes,
|
||||
@@ -343,7 +343,7 @@ describe('cross origin iframes', function (this: ISuite) {
|
||||
it('should record custom events', async () => {
|
||||
const frame = ctx.page.mainFrame().childFrames()[0];
|
||||
await frame.evaluate(() => {
|
||||
((window as unknown) as IWindow).rrweb.addCustomEvent('test', {
|
||||
(window as unknown as IWindow).rrweb.addCustomEvent('test', {
|
||||
id: 1,
|
||||
parentId: 1,
|
||||
nextId: 2,
|
||||
@@ -388,18 +388,17 @@ describe('cross origin iframes', function (this: ISuite) {
|
||||
});
|
||||
await waitForRAF(ctx.page);
|
||||
await ctx.page.evaluate(() => {
|
||||
(document.adoptedStyleSheets![0]
|
||||
.cssRules[0] as CSSStyleRule).style.setProperty('color', 'green');
|
||||
(document.adoptedStyleSheets![0]
|
||||
.cssRules[0] as CSSStyleRule).style.removeProperty('display');
|
||||
(
|
||||
document.adoptedStyleSheets![0].cssRules[0] as CSSStyleRule
|
||||
).style.setProperty('color', 'green');
|
||||
(
|
||||
document.adoptedStyleSheets![0].cssRules[0] as CSSStyleRule
|
||||
).style.removeProperty('display');
|
||||
});
|
||||
await frame.evaluate(() => {
|
||||
(document.adoptedStyleSheets![0]
|
||||
.cssRules[0] as CSSStyleRule).style.setProperty(
|
||||
'font-size',
|
||||
'medium',
|
||||
'important',
|
||||
);
|
||||
(
|
||||
document.adoptedStyleSheets![0].cssRules[0] as CSSStyleRule
|
||||
).style.setProperty('font-size', 'medium', 'important');
|
||||
document.adoptedStyleSheets![0].insertRule('h2 { color: red; }');
|
||||
});
|
||||
await waitForRAF(ctx.page);
|
||||
@@ -445,8 +444,9 @@ describe('cross origin iframes', function (this: ISuite) {
|
||||
'color',
|
||||
'green',
|
||||
);
|
||||
(document.styleSheets[0]
|
||||
.cssRules[0] as CSSStyleRule).style.removeProperty('display');
|
||||
(
|
||||
document.styleSheets[0].cssRules[0] as CSSStyleRule
|
||||
).style.removeProperty('display');
|
||||
});
|
||||
await frame.evaluate(() => {
|
||||
(document.styleSheets[0].cssRules[0] as CSSStyleRule).style.setProperty(
|
||||
@@ -596,7 +596,7 @@ describe('same origin iframes', function (this: ISuite) {
|
||||
|
||||
it('should emit contents of iframe once', async () => {
|
||||
const events = await ctx.page.evaluate(
|
||||
() => ((window as unknown) as IWindow).snapshots,
|
||||
() => (window as unknown as IWindow).snapshots,
|
||||
);
|
||||
await waitForRAF(ctx.page);
|
||||
// two events (full snapshot + meta) from main frame,
|
||||
|
||||
@@ -64,13 +64,13 @@ const setup = function (
|
||||
ctx.page.on('console', (msg) => console.log('PAGE LOG:', msg.text()));
|
||||
|
||||
await ctx.page.evaluate((canvasSample) => {
|
||||
const { record } = ((window as unknown) as IWindow).rrweb;
|
||||
const { record } = (window as unknown as IWindow).rrweb;
|
||||
record({
|
||||
recordCanvas: true,
|
||||
sampling: {
|
||||
canvas: canvasSample,
|
||||
},
|
||||
emit: ((window as unknown) as IWindow).emit,
|
||||
emit: (window as unknown as IWindow).emit,
|
||||
});
|
||||
}, canvasSample);
|
||||
});
|
||||
|
||||
@@ -22,9 +22,9 @@ describe('webglMutation', () => {
|
||||
const createShaderMock = jest.fn().mockImplementation(() => {
|
||||
return new WebGLShader();
|
||||
});
|
||||
const context = ({
|
||||
const context = {
|
||||
createShader: createShaderMock,
|
||||
} as unknown) as WebGLRenderingContext;
|
||||
} as unknown as WebGLRenderingContext;
|
||||
jest.spyOn(canvas, 'getContext').mockImplementation(() => {
|
||||
return context;
|
||||
});
|
||||
|
||||
@@ -597,7 +597,9 @@ describe('replayer', function () {
|
||||
expect(
|
||||
await iframeTwoDocument!.evaluate(
|
||||
(iframe) => (iframe as HTMLIFrameElement)!.contentDocument!.doctype,
|
||||
(await iframeTwoDocument!.$$('iframe'))[1],
|
||||
(
|
||||
await iframeTwoDocument!.$$('iframe')
|
||||
)[1],
|
||||
),
|
||||
).not.toBeNull();
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@ import * as url from 'url';
|
||||
import * as fs from 'fs';
|
||||
|
||||
export async function launchPuppeteer(
|
||||
options?: Parameters<typeof puppeteer['launch']>[0],
|
||||
options?: Parameters<(typeof puppeteer)['launch']>[0],
|
||||
) {
|
||||
return await puppeteer.launch({
|
||||
headless: process.env.PUPPETEER_HEADLESS ? true : false,
|
||||
@@ -119,7 +119,8 @@ function stringifySnapshots(snapshots: eventWithTime[]): string {
|
||||
s.data.href = 'about:blank';
|
||||
}
|
||||
// FIXME: travis coordinates seems different with my laptop
|
||||
const coordinatesReg = /(bottom|top|left|right|width|height): \d+(\.\d+)?px/g;
|
||||
const coordinatesReg =
|
||||
/(bottom|top|left|right|width|height): \d+(\.\d+)?px/g;
|
||||
if (
|
||||
s.type === EventType.IncrementalSnapshot &&
|
||||
s.data.source === IncrementalSource.MouseInteraction
|
||||
@@ -178,10 +179,8 @@ function stringifySnapshots(snapshots: eventWithTime[]): string {
|
||||
add.node.attributes.rr_dataURL &&
|
||||
typeof add.node.attributes.rr_dataURL === 'string'
|
||||
) {
|
||||
add.node.attributes.rr_dataURL = add.node.attributes.rr_dataURL.replace(
|
||||
/,.+$/,
|
||||
',...',
|
||||
);
|
||||
add.node.attributes.rr_dataURL =
|
||||
add.node.attributes.rr_dataURL.replace(/,.+$/, ',...');
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -284,7 +283,7 @@ export function stripBase64(events: eventWithTime[]) {
|
||||
const base64Strings: string[] = [];
|
||||
function walk<T>(obj: T): T {
|
||||
if (!obj || typeof obj !== 'object') return obj;
|
||||
if (Array.isArray(obj)) return (obj.map((e) => walk(e)) as unknown) as T;
|
||||
if (Array.isArray(obj)) return obj.map((e) => walk(e)) as unknown as T;
|
||||
const newObj: Partial<T> = {};
|
||||
for (const prop in obj) {
|
||||
const value = obj[prop];
|
||||
|
||||
Reference in New Issue
Block a user