Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rrweb

Package Overview
Dependencies
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rrweb - npm Package Compare versions

Comparing version 1.0.0-beta.1 to 1.0.0-beta.2

4

dist/plugins/console-replay.js

@@ -245,3 +245,3 @@ var rrwebConsoleReplay = (function (exports) {

}());
var getLogReplayPlugin = function (options) {
var getReplayConsolePlugin = function (options) {
var replayLogger = (options === null || options === void 0 ? void 0 : options.replayLogger) || new LogReplayPlugin(options).getConsoleLogger();

@@ -275,3 +275,3 @@ return {

exports.getLogReplayPlugin = getLogReplayPlugin;
exports.getReplayConsolePlugin = getReplayConsolePlugin;

@@ -278,0 +278,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

@@ -15,3 +15,3 @@ var rrwebConsoleReplay=function(e){"use strict";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function o(e,o){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,r,a=t.call(e),l=[];try{for(;(void 0===o||o-- >0)&&!(n=a.next()).done;)l.push(n.value)}catch(e){r={error:e}}finally{try{n&&!n.done&&(t=a.return)&&t.call(a)}finally{if(r)throw r.error}}return l}function t(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(o(arguments[t]));return e}var n,r,a,l,u,i;!function(e){e[e.DomContentLoaded=0]="DomContentLoaded",e[e.Load=1]="Load",e[e.FullSnapshot=2]="FullSnapshot",e[e.IncrementalSnapshot=3]="IncrementalSnapshot",e[e.Meta=4]="Meta",e[e.Custom=5]="Custom",e[e.Plugin=6]="Plugin"}(n||(n={})),function(e){e[e.Mutation=0]="Mutation",e[e.MouseMove=1]="MouseMove",e[e.MouseInteraction=2]="MouseInteraction",e[e.Scroll=3]="Scroll",e[e.ViewportResize=4]="ViewportResize",e[e.Input=5]="Input",e[e.TouchMove=6]="TouchMove",e[e.MediaInteraction=7]="MediaInteraction",e[e.StyleSheetRule=8]="StyleSheetRule",e[e.CanvasMutation=9]="CanvasMutation",e[e.Font=10]="Font",e[e.Log=11]="Log",e[e.Drag=12]="Drag"}(r||(r={})),function(e){e[e.MouseUp=0]="MouseUp",e[e.MouseDown=1]="MouseDown",e[e.Click=2]="Click",e[e.ContextMenu=3]="ContextMenu",e[e.DblClick=4]="DblClick",e[e.Focus=5]="Focus",e[e.Blur=6]="Blur",e[e.TouchStart=7]="TouchStart",e[e.TouchMove_Departed=8]="TouchMove_Departed",e[e.TouchEnd=9]="TouchEnd"}(a||(a={})),function(e){e[e.Play=0]="Play",e[e.Pause=1]="Pause",e[e.Seeked=2]="Seeked"}(l||(l={})),function(e){e.Start="start",e.Pause="pause",e.Resume="resume",e.Resize="resize",e.Finish="finish",e.FullsnapshotRebuilded="fullsnapshot-rebuilded",e.LoadStylesheetStart="load-stylesheet-start",e.LoadStylesheetEnd="load-stylesheet-end",e.SkipStart="skip-start",e.SkipEnd="skip-end",e.MouseInteraction="mouse-interaction",e.EventCast="event-cast",e.CustomEvent="custom-event",e.Flush="flush",e.StateChange="state-change",e.PlayBack="play-back"}(u||(u={})),function(e){e[e.Document=0]="Document",e[e.DocumentType=1]="DocumentType",e[e.Element=2]="Element",e[e.Text=3]="Text",e[e.CDATA=4]="CDATA",e[e.Comment=5]="Comment"}(i||(i={}));var c="Please stop import mirror directly. Instead of that,\r\nnow you can use replayer.getMirror() to access the mirror instance of a replayer,\r\nor you can use record.mirror to access the mirror instance during recording.",s={map:{},getId:function(){return console.error(c),-1},getNode:function(){return console.error(c),null},removeNodeFromMap:function(){console.error(c)},has:function(){return console.error(c),!1},reset:function(){console.error(c)}};"undefined"!=typeof window&&window.Proxy&&window.Reflect&&(s=new Proxy(s,{get:function(e,o,t){return"map"===o&&console.error(c),Reflect.get(e,o,t)}}));var d={level:["assert","clear","count","countReset","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","table","time","timeEnd","timeLog","trace","warn"],replayLogger:void 0},f=function(){function e(e){this.config=Object.assign(d,e)}return e.prototype.getConsoleLogger=function(){var e,o,n=this,r={},a=function(e){r[e]="trace"===e?function(e){(console.log.__rrweb_original__?console.log.__rrweb_original__:console.log).apply(void 0,t(e.payload.map((function(e){return JSON.parse(e)})),[n.formatMessage(e)]))}:function(o){(console[e].__rrweb_original__?console[e].__rrweb_original__:console[e]).apply(void 0,t(o.payload.map((function(e){return JSON.parse(e)})),[n.formatMessage(o)]))}};try{for(var l=function(e){var o="function"==typeof Symbol&&Symbol.iterator,t=o&&e[o],n=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(o?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.config.level),u=l.next();!u.done;u=l.next()){a(u.value)}}catch(o){e={error:o}}finally{try{u&&!u.done&&(o=l.return)&&o.call(l)}finally{if(e)throw e.error}}return r},e.prototype.formatMessage=function(e){if(0===e.trace.length)return"";var o="\n\tat ";return o+=e.trace.join("\n\tat ")},e}();return e.getLogReplayPlugin=function(e){var o=(null==e?void 0:e.replayLogger)||new f(e).getConsoleLogger();return{handler:function(e,t,a){var l=null;if(e.type===n.IncrementalSnapshot&&e.data.source===r.Log?l=e.data:e.type===n.Plugin&&"rrweb/console@1"===e.data.plugin&&(l=e.data.payload),l)try{"function"==typeof o[l.level]&&o[l.level](l)}catch(e){a.replayer.config.showWarning&&console.warn(e)}}}},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
***************************************************************************** */function o(e,o){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,r,a=t.call(e),l=[];try{for(;(void 0===o||o-- >0)&&!(n=a.next()).done;)l.push(n.value)}catch(e){r={error:e}}finally{try{n&&!n.done&&(t=a.return)&&t.call(a)}finally{if(r)throw r.error}}return l}function t(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(o(arguments[t]));return e}var n,r,a,l,u,i;!function(e){e[e.DomContentLoaded=0]="DomContentLoaded",e[e.Load=1]="Load",e[e.FullSnapshot=2]="FullSnapshot",e[e.IncrementalSnapshot=3]="IncrementalSnapshot",e[e.Meta=4]="Meta",e[e.Custom=5]="Custom",e[e.Plugin=6]="Plugin"}(n||(n={})),function(e){e[e.Mutation=0]="Mutation",e[e.MouseMove=1]="MouseMove",e[e.MouseInteraction=2]="MouseInteraction",e[e.Scroll=3]="Scroll",e[e.ViewportResize=4]="ViewportResize",e[e.Input=5]="Input",e[e.TouchMove=6]="TouchMove",e[e.MediaInteraction=7]="MediaInteraction",e[e.StyleSheetRule=8]="StyleSheetRule",e[e.CanvasMutation=9]="CanvasMutation",e[e.Font=10]="Font",e[e.Log=11]="Log",e[e.Drag=12]="Drag"}(r||(r={})),function(e){e[e.MouseUp=0]="MouseUp",e[e.MouseDown=1]="MouseDown",e[e.Click=2]="Click",e[e.ContextMenu=3]="ContextMenu",e[e.DblClick=4]="DblClick",e[e.Focus=5]="Focus",e[e.Blur=6]="Blur",e[e.TouchStart=7]="TouchStart",e[e.TouchMove_Departed=8]="TouchMove_Departed",e[e.TouchEnd=9]="TouchEnd"}(a||(a={})),function(e){e[e.Play=0]="Play",e[e.Pause=1]="Pause",e[e.Seeked=2]="Seeked"}(l||(l={})),function(e){e.Start="start",e.Pause="pause",e.Resume="resume",e.Resize="resize",e.Finish="finish",e.FullsnapshotRebuilded="fullsnapshot-rebuilded",e.LoadStylesheetStart="load-stylesheet-start",e.LoadStylesheetEnd="load-stylesheet-end",e.SkipStart="skip-start",e.SkipEnd="skip-end",e.MouseInteraction="mouse-interaction",e.EventCast="event-cast",e.CustomEvent="custom-event",e.Flush="flush",e.StateChange="state-change",e.PlayBack="play-back"}(u||(u={})),function(e){e[e.Document=0]="Document",e[e.DocumentType=1]="DocumentType",e[e.Element=2]="Element",e[e.Text=3]="Text",e[e.CDATA=4]="CDATA",e[e.Comment=5]="Comment"}(i||(i={}));var c="Please stop import mirror directly. Instead of that,\r\nnow you can use replayer.getMirror() to access the mirror instance of a replayer,\r\nor you can use record.mirror to access the mirror instance during recording.",s={map:{},getId:function(){return console.error(c),-1},getNode:function(){return console.error(c),null},removeNodeFromMap:function(){console.error(c)},has:function(){return console.error(c),!1},reset:function(){console.error(c)}};"undefined"!=typeof window&&window.Proxy&&window.Reflect&&(s=new Proxy(s,{get:function(e,o,t){return"map"===o&&console.error(c),Reflect.get(e,o,t)}}));var d={level:["assert","clear","count","countReset","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","table","time","timeEnd","timeLog","trace","warn"],replayLogger:void 0},f=function(){function e(e){this.config=Object.assign(d,e)}return e.prototype.getConsoleLogger=function(){var e,o,n=this,r={},a=function(e){r[e]="trace"===e?function(e){(console.log.__rrweb_original__?console.log.__rrweb_original__:console.log).apply(void 0,t(e.payload.map((function(e){return JSON.parse(e)})),[n.formatMessage(e)]))}:function(o){(console[e].__rrweb_original__?console[e].__rrweb_original__:console[e]).apply(void 0,t(o.payload.map((function(e){return JSON.parse(e)})),[n.formatMessage(o)]))}};try{for(var l=function(e){var o="function"==typeof Symbol&&Symbol.iterator,t=o&&e[o],n=0;if(t)return t.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(o?"Object is not iterable.":"Symbol.iterator is not defined.")}(this.config.level),u=l.next();!u.done;u=l.next()){a(u.value)}}catch(o){e={error:o}}finally{try{u&&!u.done&&(o=l.return)&&o.call(l)}finally{if(e)throw e.error}}return r},e.prototype.formatMessage=function(e){if(0===e.trace.length)return"";var o="\n\tat ";return o+=e.trace.join("\n\tat ")},e}();return e.getReplayConsolePlugin=function(e){var o=(null==e?void 0:e.replayLogger)||new f(e).getConsoleLogger();return{handler:function(e,t,a){var l=null;if(e.type===n.IncrementalSnapshot&&e.data.source===r.Log?l=e.data:e.type===n.Plugin&&"rrweb/console@1"===e.data.plugin&&(l=e.data.payload),l)try{"function"==typeof o[l.level]&&o[l.level](l)}catch(e){a.replayer.config.showWarning&&console.warn(e)}}}},Object.defineProperty(e,"__esModule",{value:!0}),e}({});
//# sourceMappingURL=console-replay.min.js.map

@@ -11,2 +11,1448 @@ var NodeType;

export { NodeType };
function isElement(n) {
return n.nodeType === n.ELEMENT_NODE;
}
function isShadowRoot(n) {
var _a;
var host = (_a = n) === null || _a === void 0 ? void 0 : _a.host;
return Boolean(host && host.shadowRoot && host.shadowRoot === n);
}
function maskInputValue(_a) {
var maskInputOptions = _a.maskInputOptions, tagName = _a.tagName, type = _a.type, value = _a.value, maskInputFn = _a.maskInputFn;
var text = value || '';
if (maskInputOptions[tagName.toLowerCase()] ||
maskInputOptions[type]) {
if (maskInputFn) {
text = maskInputFn(text);
}
else {
text = '*'.repeat(text.length);
}
}
return text;
}
var _id = 1;
var tagNameRegex = RegExp('[^a-z0-9-_:]');
var IGNORED_NODE = -2;
function genId() {
return _id++;
}
function getValidTagName(element) {
if (element instanceof HTMLFormElement) {
return 'form';
}
var processedTagName = element.tagName.toLowerCase().trim();
if (tagNameRegex.test(processedTagName)) {
return 'div';
}
return processedTagName;
}
function getCssRulesString(s) {
try {
var rules = s.rules || s.cssRules;
return rules ? Array.from(rules).map(getCssRuleString).join('') : null;
}
catch (error) {
return null;
}
}
function getCssRuleString(rule) {
return isCSSImportRule(rule)
? getCssRulesString(rule.styleSheet) || ''
: rule.cssText;
}
function isCSSImportRule(rule) {
return 'styleSheet' in rule;
}
function extractOrigin(url) {
var origin;
if (url.indexOf('//') > -1) {
origin = url.split('/').slice(0, 3).join('/');
}
else {
origin = url.split('/')[0];
}
origin = origin.split('?')[0];
return origin;
}
var URL_IN_CSS_REF = /url\((?:(')([^']*)'|(")([^"]*)"|([^)]*))\)/gm;
var RELATIVE_PATH = /^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/;
var DATA_URI = /^(data:)([^,]*),(.*)/i;
function absoluteToStylesheet(cssText, href) {
return (cssText || '').replace(URL_IN_CSS_REF, function (origin, quote1, path1, quote2, path2, path3) {
var filePath = path1 || path2 || path3;
var maybeQuote = quote1 || quote2 || '';
if (!filePath) {
return origin;
}
if (!RELATIVE_PATH.test(filePath)) {
return "url(" + maybeQuote + filePath + maybeQuote + ")";
}
if (DATA_URI.test(filePath)) {
return "url(" + maybeQuote + filePath + maybeQuote + ")";
}
if (filePath[0] === '/') {
return "url(" + maybeQuote + (extractOrigin(href) + filePath) + maybeQuote + ")";
}
var stack = href.split('/');
var parts = filePath.split('/');
stack.pop();
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
var part = parts_1[_i];
if (part === '.') {
continue;
}
else if (part === '..') {
stack.pop();
}
else {
stack.push(part);
}
}
return "url(" + maybeQuote + stack.join('/') + maybeQuote + ")";
});
}
var SRCSET_NOT_SPACES = /^[^ \t\n\r\u000c]+/;
var SRCSET_COMMAS_OR_SPACES = /^[, \t\n\r\u000c]+/;
function getAbsoluteSrcsetString(doc, attributeValue) {
if (attributeValue.trim() === '') {
return attributeValue;
}
var pos = 0;
function collectCharacters(regEx) {
var chars, match = regEx.exec(attributeValue.substring(pos));
if (match) {
chars = match[0];
pos += chars.length;
return chars;
}
return '';
}
var output = [];
while (true) {
collectCharacters(SRCSET_COMMAS_OR_SPACES);
if (pos >= attributeValue.length) {
break;
}
var url = collectCharacters(SRCSET_NOT_SPACES);
if (url.slice(-1) === ',') {
url = absoluteToDoc(doc, url.substring(0, url.length - 1));
output.push(url);
}
else {
var descriptorsStr = '';
url = absoluteToDoc(doc, url);
var inParens = false;
while (true) {
var c = attributeValue.charAt(pos);
if (c === '') {
output.push((url + descriptorsStr).trim());
break;
}
else if (!inParens) {
if (c === ',') {
pos += 1;
output.push((url + descriptorsStr).trim());
break;
}
else if (c === '(') {
inParens = true;
}
}
else {
if (c === ')') {
inParens = false;
}
}
descriptorsStr += c;
pos += 1;
}
}
}
return output.join(', ');
}
function absoluteToDoc(doc, attributeValue) {
if (!attributeValue || attributeValue.trim() === '') {
return attributeValue;
}
var a = doc.createElement('a');
a.href = attributeValue;
return a.href;
}
function isSVGElement(el) {
return el.tagName === 'svg' || el instanceof SVGElement;
}
function getHref() {
var a = document.createElement('a');
a.href = '';
return a.href;
}
function transformAttribute(doc, tagName, name, value) {
if (name === 'src' || ((name === 'href' || name === 'xlink:href') && value)) {
return absoluteToDoc(doc, value);
}
else if (name === 'background' &&
value &&
(tagName === 'table' || tagName === 'td' || tagName === 'th')) {
return absoluteToDoc(doc, value);
}
else if (name === 'srcset' && value) {
return getAbsoluteSrcsetString(doc, value);
}
else if (name === 'style' && value) {
return absoluteToStylesheet(value, getHref());
}
else {
return value;
}
}
function _isBlockedElement(element, blockClass, blockSelector) {
if (typeof blockClass === 'string') {
if (element.classList.contains(blockClass)) {
return true;
}
}
else {
for (var eIndex = 0; eIndex < element.classList.length; eIndex++) {
var className = element.classList[eIndex];
if (blockClass.test(className)) {
return true;
}
}
}
if (blockSelector) {
return element.matches(blockSelector);
}
return false;
}
function needMaskingText(node, maskTextClass, maskTextSelector) {
if (!node) {
return false;
}
if (node.nodeType === node.ELEMENT_NODE) {
if (typeof maskTextClass === 'string') {
if (node.classList.contains(maskTextClass)) {
return true;
}
}
else {
node.classList.forEach(function (className) {
if (maskTextClass.test(className)) {
return true;
}
});
}
if (maskTextSelector) {
if (node.matches(maskTextSelector)) {
return true;
}
}
return needMaskingText(node.parentNode, maskTextClass, maskTextSelector);
}
if (node.nodeType === node.TEXT_NODE) {
return needMaskingText(node.parentNode, maskTextClass, maskTextSelector);
}
return needMaskingText(node.parentNode, maskTextClass, maskTextSelector);
}
function onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {
var win = iframeEl.contentWindow;
if (!win) {
return;
}
var fired = false;
var readyState;
try {
readyState = win.document.readyState;
}
catch (error) {
return;
}
if (readyState !== 'complete') {
var timer_1 = setTimeout(function () {
if (!fired) {
listener();
fired = true;
}
}, iframeLoadTimeout);
iframeEl.addEventListener('load', function () {
clearTimeout(timer_1);
fired = true;
listener();
});
return;
}
var blankUrl = 'about:blank';
if (win.location.href !== blankUrl ||
iframeEl.src === blankUrl ||
iframeEl.src === '') {
setTimeout(listener, 0);
return;
}
iframeEl.addEventListener('load', listener);
}
function serializeNode(n, options) {
var doc = options.doc, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, inlineStylesheet = options.inlineStylesheet, _a = options.maskInputOptions, maskInputOptions = _a === void 0 ? {} : _a, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, recordCanvas = options.recordCanvas, keepIframeSrcFn = options.keepIframeSrcFn;
var rootId;
if (doc.__sn) {
var docId = doc.__sn.id;
rootId = docId === 1 ? undefined : docId;
}
switch (n.nodeType) {
case n.DOCUMENT_NODE:
return {
type: NodeType.Document,
childNodes: [],
rootId: rootId,
};
case n.DOCUMENT_TYPE_NODE:
return {
type: NodeType.DocumentType,
name: n.name,
publicId: n.publicId,
systemId: n.systemId,
rootId: rootId,
};
case n.ELEMENT_NODE:
var needBlock = _isBlockedElement(n, blockClass, blockSelector);
var tagName = getValidTagName(n);
var attributes_1 = {};
for (var _i = 0, _b = Array.from(n.attributes); _i < _b.length; _i++) {
var _c = _b[_i], name = _c.name, value = _c.value;
attributes_1[name] = transformAttribute(doc, tagName, name, value);
}
if (tagName === 'link' && inlineStylesheet) {
var stylesheet = Array.from(doc.styleSheets).find(function (s) {
return s.href === n.href;
});
var cssText = getCssRulesString(stylesheet);
if (cssText) {
delete attributes_1.rel;
delete attributes_1.href;
attributes_1._cssText = absoluteToStylesheet(cssText, stylesheet.href);
}
}
if (tagName === 'style' &&
n.sheet &&
!(n.innerText ||
n.textContent ||
'').trim().length) {
var cssText = getCssRulesString(n.sheet);
if (cssText) {
attributes_1._cssText = absoluteToStylesheet(cssText, getHref());
}
}
if (tagName === 'input' ||
tagName === 'textarea' ||
tagName === 'select') {
var value = n.value;
if (attributes_1.type !== 'radio' &&
attributes_1.type !== 'checkbox' &&
attributes_1.type !== 'submit' &&
attributes_1.type !== 'button' &&
value) {
attributes_1.value = maskInputValue({
type: attributes_1.type,
tagName: tagName,
value: value,
maskInputOptions: maskInputOptions,
maskInputFn: maskInputFn,
});
}
else if (n.checked) {
attributes_1.checked = n.checked;
}
}
if (tagName === 'option') {
var selectValue = n.parentElement;
if (attributes_1.value === selectValue.value) {
attributes_1.selected = n.selected;
}
}
if (tagName === 'canvas' && recordCanvas) {
attributes_1.rr_dataURL = n.toDataURL();
}
if (tagName === 'audio' || tagName === 'video') {
attributes_1.rr_mediaState = n.paused
? 'paused'
: 'played';
attributes_1.rr_mediaCurrentTime = n.currentTime;
}
if (n.scrollLeft) {
attributes_1.rr_scrollLeft = n.scrollLeft;
}
if (n.scrollTop) {
attributes_1.rr_scrollTop = n.scrollTop;
}
if (needBlock) {
var _d = n.getBoundingClientRect(), width = _d.width, height = _d.height;
attributes_1 = {
class: attributes_1.class,
rr_width: width + "px",
rr_height: height + "px",
};
}
if (tagName === 'iframe' && !keepIframeSrcFn(attributes_1.src)) {
delete attributes_1.src;
}
return {
type: NodeType.Element,
tagName: tagName,
attributes: attributes_1,
childNodes: [],
isSVG: isSVGElement(n) || undefined,
needBlock: needBlock,
rootId: rootId,
};
case n.TEXT_NODE:
var parentTagName = n.parentNode && n.parentNode.tagName;
var textContent = n.textContent;
var isStyle = parentTagName === 'STYLE' ? true : undefined;
var isScript = parentTagName === 'SCRIPT' ? true : undefined;
if (isStyle && textContent) {
textContent = absoluteToStylesheet(textContent, getHref());
}
if (isScript) {
textContent = 'SCRIPT_PLACEHOLDER';
}
if (!isStyle &&
!isScript &&
needMaskingText(n, maskTextClass, maskTextSelector) &&
textContent) {
textContent = maskTextFn
? maskTextFn(textContent)
: textContent.replace(/[\S]/g, '*');
}
return {
type: NodeType.Text,
textContent: textContent || '',
isStyle: isStyle,
rootId: rootId,
};
case n.CDATA_SECTION_NODE:
return {
type: NodeType.CDATA,
textContent: '',
rootId: rootId,
};
case n.COMMENT_NODE:
return {
type: NodeType.Comment,
textContent: n.textContent || '',
rootId: rootId,
};
default:
return false;
}
}
function lowerIfExists(maybeAttr) {
if (maybeAttr === undefined) {
return '';
}
else {
return maybeAttr.toLowerCase();
}
}
function slimDOMExcluded(sn, slimDOMOptions) {
if (slimDOMOptions.comment && sn.type === NodeType.Comment) {
return true;
}
else if (sn.type === NodeType.Element) {
if (slimDOMOptions.script &&
(sn.tagName === 'script' ||
(sn.tagName === 'link' &&
sn.attributes.rel === 'preload' &&
sn.attributes.as === 'script'))) {
return true;
}
else if (slimDOMOptions.headFavicon &&
((sn.tagName === 'link' && sn.attributes.rel === 'shortcut icon') ||
(sn.tagName === 'meta' &&
(lowerIfExists(sn.attributes.name).match(/^msapplication-tile(image|color)$/) ||
lowerIfExists(sn.attributes.name) === 'application-name' ||
lowerIfExists(sn.attributes.rel) === 'icon' ||
lowerIfExists(sn.attributes.rel) === 'apple-touch-icon' ||
lowerIfExists(sn.attributes.rel) === 'shortcut icon')))) {
return true;
}
else if (sn.tagName === 'meta') {
if (slimDOMOptions.headMetaDescKeywords &&
lowerIfExists(sn.attributes.name).match(/^description|keywords$/)) {
return true;
}
else if (slimDOMOptions.headMetaSocial &&
(lowerIfExists(sn.attributes.property).match(/^(og|twitter|fb):/) ||
lowerIfExists(sn.attributes.name).match(/^(og|twitter):/) ||
lowerIfExists(sn.attributes.name) === 'pinterest')) {
return true;
}
else if (slimDOMOptions.headMetaRobots &&
(lowerIfExists(sn.attributes.name) === 'robots' ||
lowerIfExists(sn.attributes.name) === 'googlebot' ||
lowerIfExists(sn.attributes.name) === 'bingbot')) {
return true;
}
else if (slimDOMOptions.headMetaHttpEquiv &&
sn.attributes['http-equiv'] !== undefined) {
return true;
}
else if (slimDOMOptions.headMetaAuthorship &&
(lowerIfExists(sn.attributes.name) === 'author' ||
lowerIfExists(sn.attributes.name) === 'generator' ||
lowerIfExists(sn.attributes.name) === 'framework' ||
lowerIfExists(sn.attributes.name) === 'publisher' ||
lowerIfExists(sn.attributes.name) === 'progid' ||
lowerIfExists(sn.attributes.property).match(/^article:/) ||
lowerIfExists(sn.attributes.property).match(/^product:/))) {
return true;
}
else if (slimDOMOptions.headMetaVerification &&
(lowerIfExists(sn.attributes.name) === 'google-site-verification' ||
lowerIfExists(sn.attributes.name) === 'yandex-verification' ||
lowerIfExists(sn.attributes.name) === 'csrf-token' ||
lowerIfExists(sn.attributes.name) === 'p:domain_verify' ||
lowerIfExists(sn.attributes.name) === 'verify-v1' ||
lowerIfExists(sn.attributes.name) === 'verification' ||
lowerIfExists(sn.attributes.name) === 'shopify-checkout-api-token')) {
return true;
}
}
}
return false;
}
function serializeNodeWithId(n, options) {
var doc = options.doc, map = options.map, blockClass = options.blockClass, blockSelector = options.blockSelector, maskTextClass = options.maskTextClass, maskTextSelector = options.maskTextSelector, _a = options.skipChild, skipChild = _a === void 0 ? false : _a, _b = options.inlineStylesheet, inlineStylesheet = _b === void 0 ? true : _b, _c = options.maskInputOptions, maskInputOptions = _c === void 0 ? {} : _c, maskTextFn = options.maskTextFn, maskInputFn = options.maskInputFn, slimDOMOptions = options.slimDOMOptions, _d = options.recordCanvas, recordCanvas = _d === void 0 ? false : _d, onSerialize = options.onSerialize, onIframeLoad = options.onIframeLoad, _e = options.iframeLoadTimeout, iframeLoadTimeout = _e === void 0 ? 5000 : _e, _f = options.keepIframeSrcFn, keepIframeSrcFn = _f === void 0 ? function () { return false; } : _f;
var _g = options.preserveWhiteSpace, preserveWhiteSpace = _g === void 0 ? true : _g;
var _serializedNode = serializeNode(n, {
doc: doc,
blockClass: blockClass,
blockSelector: blockSelector,
maskTextClass: maskTextClass,
maskTextSelector: maskTextSelector,
inlineStylesheet: inlineStylesheet,
maskInputOptions: maskInputOptions,
maskTextFn: maskTextFn,
maskInputFn: maskInputFn,
recordCanvas: recordCanvas,
keepIframeSrcFn: keepIframeSrcFn,
});
if (!_serializedNode) {
console.warn(n, 'not serialized');
return null;
}
var id;
if ('__sn' in n) {
id = n.__sn.id;
}
else if (slimDOMExcluded(_serializedNode, slimDOMOptions) ||
(!preserveWhiteSpace &&
_serializedNode.type === NodeType.Text &&
!_serializedNode.isStyle &&
!_serializedNode.textContent.replace(/^\s+|\s+$/gm, '').length)) {
id = IGNORED_NODE;
}
else {
id = genId();
}
var serializedNode = Object.assign(_serializedNode, { id: id });
n.__sn = serializedNode;
if (id === IGNORED_NODE) {
return null;
}
map[id] = n;
if (onSerialize) {
onSerialize(n);
}
var recordChild = !skipChild;
if (serializedNode.type === NodeType.Element) {
recordChild = recordChild && !serializedNode.needBlock;
delete serializedNode.needBlock;
}
if ((serializedNode.type === NodeType.Document ||
serializedNode.type === NodeType.Element) &&
recordChild) {
if (slimDOMOptions.headWhitespace &&
_serializedNode.type === NodeType.Element &&
_serializedNode.tagName === 'head') {
preserveWhiteSpace = false;
}
var bypassOptions = {
doc: doc,
map: map,
blockClass: blockClass,
blockSelector: blockSelector,
maskTextClass: maskTextClass,
maskTextSelector: maskTextSelector,
skipChild: skipChild,
inlineStylesheet: inlineStylesheet,
maskInputOptions: maskInputOptions,
maskTextFn: maskTextFn,
maskInputFn: maskInputFn,
slimDOMOptions: slimDOMOptions,
recordCanvas: recordCanvas,
preserveWhiteSpace: preserveWhiteSpace,
onSerialize: onSerialize,
onIframeLoad: onIframeLoad,
iframeLoadTimeout: iframeLoadTimeout,
keepIframeSrcFn: keepIframeSrcFn,
};
for (var _i = 0, _h = Array.from(n.childNodes); _i < _h.length; _i++) {
var childN = _h[_i];
var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
if (serializedChildNode) {
serializedNode.childNodes.push(serializedChildNode);
}
}
if (isElement(n) && n.shadowRoot) {
serializedNode.isShadowHost = true;
for (var _j = 0, _k = Array.from(n.shadowRoot.childNodes); _j < _k.length; _j++) {
var childN = _k[_j];
var serializedChildNode = serializeNodeWithId(childN, bypassOptions);
if (serializedChildNode) {
serializedChildNode.isShadow = true;
serializedNode.childNodes.push(serializedChildNode);
}
}
}
}
if (n.parentNode && isShadowRoot(n.parentNode)) {
serializedNode.isShadow = true;
}
if (serializedNode.type === NodeType.Element &&
serializedNode.tagName === 'iframe') {
onceIframeLoaded(n, function () {
var iframeDoc = n.contentDocument;
if (iframeDoc && onIframeLoad) {
var serializedIframeNode = serializeNodeWithId(iframeDoc, {
doc: iframeDoc,
map: map,
blockClass: blockClass,
blockSelector: blockSelector,
maskTextClass: maskTextClass,
maskTextSelector: maskTextSelector,
skipChild: false,
inlineStylesheet: inlineStylesheet,
maskInputOptions: maskInputOptions,
maskTextFn: maskTextFn,
maskInputFn: maskInputFn,
slimDOMOptions: slimDOMOptions,
recordCanvas: recordCanvas,
preserveWhiteSpace: preserveWhiteSpace,
onSerialize: onSerialize,
onIframeLoad: onIframeLoad,
iframeLoadTimeout: iframeLoadTimeout,
keepIframeSrcFn: keepIframeSrcFn,
});
if (serializedIframeNode) {
onIframeLoad(n, serializedIframeNode);
}
}
}, iframeLoadTimeout);
}
return serializedNode;
}
function snapshot(n, options) {
var _a = options || {}, _b = _a.blockClass, blockClass = _b === void 0 ? 'rr-block' : _b, _c = _a.blockSelector, blockSelector = _c === void 0 ? null : _c, _d = _a.maskTextClass, maskTextClass = _d === void 0 ? 'rr-mask' : _d, _e = _a.maskTextSelector, maskTextSelector = _e === void 0 ? null : _e, _f = _a.inlineStylesheet, inlineStylesheet = _f === void 0 ? true : _f, _g = _a.recordCanvas, recordCanvas = _g === void 0 ? false : _g, _h = _a.maskAllInputs, maskAllInputs = _h === void 0 ? false : _h, maskTextFn = _a.maskTextFn, maskInputFn = _a.maskInputFn, _j = _a.slimDOM, slimDOM = _j === void 0 ? false : _j, preserveWhiteSpace = _a.preserveWhiteSpace, onSerialize = _a.onSerialize, onIframeLoad = _a.onIframeLoad, iframeLoadTimeout = _a.iframeLoadTimeout, _k = _a.keepIframeSrcFn, keepIframeSrcFn = _k === void 0 ? function () { return false; } : _k;
var idNodeMap = {};
var maskInputOptions = maskAllInputs === true
? {
color: true,
date: true,
'datetime-local': true,
email: true,
month: true,
number: true,
range: true,
search: true,
tel: true,
text: true,
time: true,
url: true,
week: true,
textarea: true,
select: true,
password: true,
}
: maskAllInputs === false
? {
password: true,
}
: maskAllInputs;
var slimDOMOptions = slimDOM === true || slimDOM === 'all'
?
{
script: true,
comment: true,
headFavicon: true,
headWhitespace: true,
headMetaDescKeywords: slimDOM === 'all',
headMetaSocial: true,
headMetaRobots: true,
headMetaHttpEquiv: true,
headMetaAuthorship: true,
headMetaVerification: true,
}
: slimDOM === false
? {}
: slimDOM;
return [
serializeNodeWithId(n, {
doc: n,
map: idNodeMap,
blockClass: blockClass,
blockSelector: blockSelector,
maskTextClass: maskTextClass,
maskTextSelector: maskTextSelector,
skipChild: false,
inlineStylesheet: inlineStylesheet,
maskInputOptions: maskInputOptions,
maskTextFn: maskTextFn,
maskInputFn: maskInputFn,
slimDOMOptions: slimDOMOptions,
recordCanvas: recordCanvas,
preserveWhiteSpace: preserveWhiteSpace,
onSerialize: onSerialize,
onIframeLoad: onIframeLoad,
iframeLoadTimeout: iframeLoadTimeout,
keepIframeSrcFn: keepIframeSrcFn,
}),
idNodeMap,
];
}
var commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
function parse(css, options) {
if (options === void 0) { options = {}; }
var lineno = 1;
var column = 1;
function updatePosition(str) {
var lines = str.match(/\n/g);
if (lines) {
lineno += lines.length;
}
var i = str.lastIndexOf('\n');
column = i === -1 ? column + str.length : str.length - i;
}
function position() {
var start = { line: lineno, column: column };
return function (node) {
node.position = new Position(start);
whitespace();
return node;
};
}
var Position = (function () {
function Position(start) {
this.start = start;
this.end = { line: lineno, column: column };
this.source = options.source;
}
return Position;
}());
Position.prototype.content = css;
var errorsList = [];
function error(msg) {
var err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
err.reason = msg;
err.filename = options.source;
err.line = lineno;
err.column = column;
err.source = css;
if (options.silent) {
errorsList.push(err);
}
else {
throw err;
}
}
function stylesheet() {
var rulesList = rules();
return {
type: 'stylesheet',
stylesheet: {
source: options.source,
rules: rulesList,
parsingErrors: errorsList,
},
};
}
function open() {
return match(/^{\s*/);
}
function close() {
return match(/^}/);
}
function rules() {
var node;
var rules = [];
whitespace();
comments(rules);
while (css.length && css.charAt(0) !== '}' && (node = atrule() || rule())) {
if (node !== false) {
rules.push(node);
comments(rules);
}
}
return rules;
}
function match(re) {
var m = re.exec(css);
if (!m) {
return;
}
var str = m[0];
updatePosition(str);
css = css.slice(str.length);
return m;
}
function whitespace() {
match(/^\s*/);
}
function comments(rules) {
if (rules === void 0) { rules = []; }
var c;
while ((c = comment())) {
if (c !== false) {
rules.push(c);
}
c = comment();
}
return rules;
}
function comment() {
var pos = position();
if ('/' !== css.charAt(0) || '*' !== css.charAt(1)) {
return;
}
var i = 2;
while ('' !== css.charAt(i) &&
('*' !== css.charAt(i) || '/' !== css.charAt(i + 1))) {
++i;
}
i += 2;
if ('' === css.charAt(i - 1)) {
return error('End of comment missing');
}
var str = css.slice(2, i - 2);
column += 2;
updatePosition(str);
css = css.slice(i);
column += 2;
return pos({
type: 'comment',
comment: str,
});
}
function selector() {
var m = match(/^([^{]+)/);
if (!m) {
return;
}
return trim(m[0])
.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
.replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function (m) {
return m.replace(/,/g, '\u200C');
})
.split(/\s*(?![^(]*\)),\s*/)
.map(function (s) {
return s.replace(/\u200C/g, ',');
});
}
function declaration() {
var pos = position();
var propMatch = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
if (!propMatch) {
return;
}
var prop = trim(propMatch[0]);
if (!match(/^:\s*/)) {
return error("property missing ':'");
}
var val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
var ret = pos({
type: 'declaration',
property: prop.replace(commentre, ''),
value: val ? trim(val[0]).replace(commentre, '') : '',
});
match(/^[;\s]*/);
return ret;
}
function declarations() {
var decls = [];
if (!open()) {
return error("missing '{'");
}
comments(decls);
var decl;
while ((decl = declaration())) {
if (decl !== false) {
decls.push(decl);
comments(decls);
}
decl = declaration();
}
if (!close()) {
return error("missing '}'");
}
return decls;
}
function keyframe() {
var m;
var vals = [];
var pos = position();
while ((m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/))) {
vals.push(m[1]);
match(/^,\s*/);
}
if (!vals.length) {
return;
}
return pos({
type: 'keyframe',
values: vals,
declarations: declarations(),
});
}
function atkeyframes() {
var pos = position();
var m = match(/^@([-\w]+)?keyframes\s*/);
if (!m) {
return;
}
var vendor = m[1];
m = match(/^([-\w]+)\s*/);
if (!m) {
return error('@keyframes missing name');
}
var name = m[1];
if (!open()) {
return error("@keyframes missing '{'");
}
var frame;
var frames = comments();
while ((frame = keyframe())) {
frames.push(frame);
frames = frames.concat(comments());
}
if (!close()) {
return error("@keyframes missing '}'");
}
return pos({
type: 'keyframes',
name: name,
vendor: vendor,
keyframes: frames,
});
}
function atsupports() {
var pos = position();
var m = match(/^@supports *([^{]+)/);
if (!m) {
return;
}
var supports = trim(m[1]);
if (!open()) {
return error("@supports missing '{'");
}
var style = comments().concat(rules());
if (!close()) {
return error("@supports missing '}'");
}
return pos({
type: 'supports',
supports: supports,
rules: style,
});
}
function athost() {
var pos = position();
var m = match(/^@host\s*/);
if (!m) {
return;
}
if (!open()) {
return error("@host missing '{'");
}
var style = comments().concat(rules());
if (!close()) {
return error("@host missing '}'");
}
return pos({
type: 'host',
rules: style,
});
}
function atmedia() {
var pos = position();
var m = match(/^@media *([^{]+)/);
if (!m) {
return;
}
var media = trim(m[1]);
if (!open()) {
return error("@media missing '{'");
}
var style = comments().concat(rules());
if (!close()) {
return error("@media missing '}'");
}
return pos({
type: 'media',
media: media,
rules: style,
});
}
function atcustommedia() {
var pos = position();
var m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
if (!m) {
return;
}
return pos({
type: 'custom-media',
name: trim(m[1]),
media: trim(m[2]),
});
}
function atpage() {
var pos = position();
var m = match(/^@page */);
if (!m) {
return;
}
var sel = selector() || [];
if (!open()) {
return error("@page missing '{'");
}
var decls = comments();
var decl;
while ((decl = declaration())) {
decls.push(decl);
decls = decls.concat(comments());
}
if (!close()) {
return error("@page missing '}'");
}
return pos({
type: 'page',
selectors: sel,
declarations: decls,
});
}
function atdocument() {
var pos = position();
var m = match(/^@([-\w]+)?document *([^{]+)/);
if (!m) {
return;
}
var vendor = trim(m[1]);
var doc = trim(m[2]);
if (!open()) {
return error("@document missing '{'");
}
var style = comments().concat(rules());
if (!close()) {
return error("@document missing '}'");
}
return pos({
type: 'document',
document: doc,
vendor: vendor,
rules: style,
});
}
function atfontface() {
var pos = position();
var m = match(/^@font-face\s*/);
if (!m) {
return;
}
if (!open()) {
return error("@font-face missing '{'");
}
var decls = comments();
var decl;
while ((decl = declaration())) {
decls.push(decl);
decls = decls.concat(comments());
}
if (!close()) {
return error("@font-face missing '}'");
}
return pos({
type: 'font-face',
declarations: decls,
});
}
var atimport = _compileAtrule('import');
var atcharset = _compileAtrule('charset');
var atnamespace = _compileAtrule('namespace');
function _compileAtrule(name) {
var re = new RegExp('^@' + name + '\\s*([^;]+);');
return function () {
var pos = position();
var m = match(re);
if (!m) {
return;
}
var ret = { type: name };
ret[name] = m[1].trim();
return pos(ret);
};
}
function atrule() {
if (css[0] !== '@') {
return;
}
return (atkeyframes() ||
atmedia() ||
atcustommedia() ||
atsupports() ||
atimport() ||
atcharset() ||
atnamespace() ||
atdocument() ||
atpage() ||
athost() ||
atfontface());
}
function rule() {
var pos = position();
var sel = selector();
if (!sel) {
return error('selector missing');
}
comments();
return pos({
type: 'rule',
selectors: sel,
declarations: declarations(),
});
}
return addParent(stylesheet());
}
function trim(str) {
return str ? str.replace(/^\s+|\s+$/g, '') : '';
}
function addParent(obj, parent) {
var isNode = obj && typeof obj.type === 'string';
var childParent = isNode ? obj : parent;
for (var _i = 0, _a = Object.keys(obj); _i < _a.length; _i++) {
var k = _a[_i];
var value = obj[k];
if (Array.isArray(value)) {
value.forEach(function (v) {
addParent(v, childParent);
});
}
else if (value && typeof value === 'object') {
addParent(value, childParent);
}
}
if (isNode) {
Object.defineProperty(obj, 'parent', {
configurable: true,
writable: true,
enumerable: false,
value: parent || null,
});
}
return obj;
}
var tagMap = {
script: 'noscript',
altglyph: 'altGlyph',
altglyphdef: 'altGlyphDef',
altglyphitem: 'altGlyphItem',
animatecolor: 'animateColor',
animatemotion: 'animateMotion',
animatetransform: 'animateTransform',
clippath: 'clipPath',
feblend: 'feBlend',
fecolormatrix: 'feColorMatrix',
fecomponenttransfer: 'feComponentTransfer',
fecomposite: 'feComposite',
feconvolvematrix: 'feConvolveMatrix',
fediffuselighting: 'feDiffuseLighting',
fedisplacementmap: 'feDisplacementMap',
fedistantlight: 'feDistantLight',
fedropshadow: 'feDropShadow',
feflood: 'feFlood',
fefunca: 'feFuncA',
fefuncb: 'feFuncB',
fefuncg: 'feFuncG',
fefuncr: 'feFuncR',
fegaussianblur: 'feGaussianBlur',
feimage: 'feImage',
femerge: 'feMerge',
femergenode: 'feMergeNode',
femorphology: 'feMorphology',
feoffset: 'feOffset',
fepointlight: 'fePointLight',
fespecularlighting: 'feSpecularLighting',
fespotlight: 'feSpotLight',
fetile: 'feTile',
feturbulence: 'feTurbulence',
foreignobject: 'foreignObject',
glyphref: 'glyphRef',
lineargradient: 'linearGradient',
radialgradient: 'radialGradient',
};
function getTagName(n) {
var tagName = tagMap[n.tagName] ? tagMap[n.tagName] : n.tagName;
if (tagName === 'link' && n.attributes._cssText) {
tagName = 'style';
}
return tagName;
}
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
var HOVER_SELECTOR = /([^\\]):hover/;
var HOVER_SELECTOR_GLOBAL = new RegExp(HOVER_SELECTOR, 'g');
function addHoverClass(cssText) {
var ast = parse(cssText, {
silent: true,
});
if (!ast.stylesheet) {
return cssText;
}
var selectors = [];
ast.stylesheet.rules.forEach(function (rule) {
if ('selectors' in rule) {
(rule.selectors || []).forEach(function (selector) {
if (HOVER_SELECTOR.test(selector)) {
selectors.push(selector);
}
});
}
});
if (selectors.length === 0)
return cssText;
var selectorMatcher = new RegExp(selectors
.filter(function (selector, index) { return selectors.indexOf(selector) === index; })
.sort(function (a, b) { return b.length - a.length; })
.map(function (selector) {
return escapeRegExp(selector);
})
.join('|'), 'g');
return cssText.replace(selectorMatcher, function (selector) {
var newSelector = selector.replace(HOVER_SELECTOR_GLOBAL, '$1.\\:hover');
return selector + ", " + newSelector;
});
}
function buildNode(n, options) {
var doc = options.doc, hackCss = options.hackCss;
switch (n.type) {
case NodeType.Document:
return doc.implementation.createDocument(null, '', null);
case NodeType.DocumentType:
return doc.implementation.createDocumentType(n.name || 'html', n.publicId, n.systemId);
case NodeType.Element:
var tagName = getTagName(n);
var node_1;
if (n.isSVG) {
node_1 = doc.createElementNS('http://www.w3.org/2000/svg', tagName);
}
else {
node_1 = doc.createElement(tagName);
}
var _loop_1 = function (name) {
if (!n.attributes.hasOwnProperty(name)) {
return "continue";
}
var value = n.attributes[name];
value =
typeof value === 'boolean' || typeof value === 'number' ? '' : value;
if (!name.startsWith('rr_')) {
var isTextarea = tagName === 'textarea' && name === 'value';
var isRemoteOrDynamicCss = tagName === 'style' && name === '_cssText';
if (isRemoteOrDynamicCss && hackCss) {
value = addHoverClass(value);
}
if (isTextarea || isRemoteOrDynamicCss) {
var child = doc.createTextNode(value);
for (var _i = 0, _a = Array.from(node_1.childNodes); _i < _a.length; _i++) {
var c = _a[_i];
if (c.nodeType === node_1.TEXT_NODE) {
node_1.removeChild(c);
}
}
node_1.appendChild(child);
return "continue";
}
try {
if (n.isSVG && name === 'xlink:href') {
node_1.setAttributeNS('http://www.w3.org/1999/xlink', name, value);
}
else if (name === 'onload' ||
name === 'onclick' ||
name.substring(0, 7) === 'onmouse') {
node_1.setAttribute('_' + name, value);
}
else if (tagName === 'meta' &&
n.attributes['http-equiv'] === 'Content-Security-Policy' &&
name == 'content') {
node_1.setAttribute('csp-content', value);
return "continue";
}
else {
node_1.setAttribute(name, value);
}
}
catch (error) {
}
}
else {
if (tagName === 'canvas' && name === 'rr_dataURL') {
var image_1 = document.createElement('img');
image_1.src = value;
image_1.onload = function () {
var ctx = node_1.getContext('2d');
if (ctx) {
ctx.drawImage(image_1, 0, 0, image_1.width, image_1.height);
}
};
}
if (name === 'rr_width') {
node_1.style.width = value;
}
if (name === 'rr_height') {
node_1.style.height = value;
}
if (name === 'rr_mediaCurrentTime') {
node_1.currentTime = n.attributes
.rr_mediaCurrentTime;
}
if (name === 'rr_mediaState') {
switch (value) {
case 'played':
node_1
.play()
.catch(function (e) { return console.warn('media playback error', e); });
break;
case 'paused':
node_1.pause();
break;
}
}
}
};
for (var name in n.attributes) {
_loop_1(name);
}
if (n.isShadowHost) {
if (!node_1.shadowRoot) {
node_1.attachShadow({ mode: 'open' });
}
else {
while (node_1.shadowRoot.firstChild) {
node_1.shadowRoot.removeChild(node_1.shadowRoot.firstChild);
}
}
}
return node_1;
case NodeType.Text:
return doc.createTextNode(n.isStyle && hackCss ? addHoverClass(n.textContent) : n.textContent);
case NodeType.CDATA:
return doc.createCDATASection(n.textContent);
case NodeType.Comment:
return doc.createComment(n.textContent);
default:
return null;
}
}
function buildNodeWithSN(n, options) {
var doc = options.doc, map = options.map, _a = options.skipChild, skipChild = _a === void 0 ? false : _a, _b = options.hackCss, hackCss = _b === void 0 ? true : _b, afterAppend = options.afterAppend;
var node = buildNode(n, { doc: doc, hackCss: hackCss });
if (!node) {
return null;
}
if (n.rootId) {
console.assert(map[n.rootId] === doc, 'Target document should has the same root id.');
}
if (n.type === NodeType.Document) {
doc.close();
doc.open();
node = doc;
}
node.__sn = n;
map[n.id] = node;
if ((n.type === NodeType.Document || n.type === NodeType.Element) &&
!skipChild) {
for (var _i = 0, _c = n.childNodes; _i < _c.length; _i++) {
var childN = _c[_i];
var childNode = buildNodeWithSN(childN, {
doc: doc,
map: map,
skipChild: false,
hackCss: hackCss,
afterAppend: afterAppend,
});
if (!childNode) {
console.warn('Failed to rebuild', childN);
continue;
}
if (childN.isShadow && isElement(node) && node.shadowRoot) {
node.shadowRoot.appendChild(childNode);
}
else {
node.appendChild(childNode);
}
if (afterAppend) {
afterAppend(childNode);
}
}
}
return node;
}
function visit(idNodeMap, onVisit) {
function walk(node) {
onVisit(node);
}
for (var key in idNodeMap) {
if (idNodeMap[key]) {
walk(idNodeMap[key]);
}
}
}
function handleScroll(node) {
var n = node.__sn;
if (n.type !== NodeType.Element) {
return;
}
var el = node;
for (var name in n.attributes) {
if (!(n.attributes.hasOwnProperty(name) && name.startsWith('rr_'))) {
continue;
}
var value = n.attributes[name];
if (name === 'rr_scrollLeft') {
el.scrollLeft = value;
}
if (name === 'rr_scrollTop') {
el.scrollTop = value;
}
}
}
function rebuild(n, options) {
var doc = options.doc, onVisit = options.onVisit, _a = options.hackCss, hackCss = _a === void 0 ? true : _a, afterAppend = options.afterAppend;
var idNodeMap = {};
var node = buildNodeWithSN(n, {
doc: doc,
map: idNodeMap,
skipChild: false,
hackCss: hackCss,
afterAppend: afterAppend,
});
visit(idNodeMap, function (visitedNode) {
if (onVisit) {
onVisit(visitedNode);
}
handleScroll(visitedNode);
});
return [node, idNodeMap];
}
export { IGNORED_NODE, NodeType, addHoverClass, buildNodeWithSN, isElement, isShadowRoot, maskInputValue, needMaskingText, rebuild, serializeNodeWithId, snapshot, transformAttribute };

@@ -16,2 +16,13 @@ /*! *****************************************************************************

var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __values(o) {

@@ -52,2 +63,2 @@ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;

export { __read, __spread, __values };
export { __assign, __read, __spread, __values };

@@ -11,2 +11,2 @@ export { EventType, IncrementalSource, MouseInteractions, ReplayerEvents } from '../types.js';

export { PLUGIN_NAME, getRecordConsolePlugin } from '../plugins/console/record/index.js';
export { getLogReplayPlugin } from '../plugins/console/replay/index.js';
export { getReplayConsolePlugin } from '../plugins/console/replay/index.js';

@@ -1,5 +0,129 @@

import '../../../utils.js';
import { __values, __spread } from '../../../../ext/tslib/tslib.es6.js';
import { patch } from '../../../utils.js';
import { stringify } from './stringify.js';
import { ErrorStackParser } from './error-stack-parser.js';
var defaultLogOptions = {
level: [
'assert',
'clear',
'count',
'countReset',
'debug',
'dir',
'dirxml',
'error',
'group',
'groupCollapsed',
'groupEnd',
'info',
'log',
'table',
'time',
'timeEnd',
'timeLog',
'trace',
'warn',
],
lengthThreshold: 1000,
logger: console,
};
function initLogObserver(cb, logOptions) {
var e_1, _a;
var _this = this;
var logger = logOptions.logger;
if (!logger) {
return function () { };
}
var logCount = 0;
var cancelHandlers = [];
if (logOptions.level.includes('error')) {
if (window) {
var originalOnError_1 = window.onerror;
window.onerror = function (msg, file, line, col, error) {
if (originalOnError_1) {
originalOnError_1.apply(_this, [msg, file, line, col, error]);
}
var trace = ErrorStackParser.parse(error).map(function (stackFrame) { return stackFrame.toString(); });
var payload = [stringify(msg, logOptions.stringifyOptions)];
cb({
level: 'error',
trace: trace,
payload: payload,
});
};
cancelHandlers.push(function () {
window.onerror = originalOnError_1;
});
}
}
try {
for (var _b = __values(logOptions.level), _c = _b.next(); !_c.done; _c = _b.next()) {
var levelType = _c.value;
cancelHandlers.push(replace(logger, levelType));
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return function () {
cancelHandlers.forEach(function (h) { return h(); });
};
function replace(_logger, level) {
var _this = this;
if (!_logger[level]) {
return function () { };
}
return patch(_logger, level, function (original) {
return function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
original.apply(_this, args);
try {
var trace = ErrorStackParser.parse(new Error())
.map(function (stackFrame) { return stackFrame.toString(); })
.splice(1);
var payload = args.map(function (s) {
return stringify(s, logOptions.stringifyOptions);
});
logCount++;
if (logCount < logOptions.lengthThreshold) {
cb({
level: level,
trace: trace,
payload: payload,
});
}
else if (logCount === logOptions.lengthThreshold) {
cb({
level: 'warn',
trace: [],
payload: [
stringify('The number of log records reached the threshold.'),
],
});
}
}
catch (error) {
original.apply(void 0, __spread(['rrweb logger error:', error], args));
}
};
});
}
}
var PLUGIN_NAME = 'rrweb/console@1';
var getRecordConsolePlugin = function (options) { return ({
name: PLUGIN_NAME,
observer: initLogObserver,
options: options
? Object.assign({}, defaultLogOptions, options)
: defaultLogOptions,
}); };
export { PLUGIN_NAME };
export { PLUGIN_NAME, getRecordConsolePlugin };

@@ -82,3 +82,3 @@ import { __values, __spread } from '../../../../ext/tslib/tslib.es6.js';

}());
var getLogReplayPlugin = function (options) {
var getReplayConsolePlugin = function (options) {
var replayLogger = (options === null || options === void 0 ? void 0 : options.replayLogger) || new LogReplayPlugin(options).getConsoleLogger();

@@ -112,2 +112,2 @@ return {

export { getLogReplayPlugin };
export { getReplayConsolePlugin };

@@ -1,4 +0,41 @@

import './types.js';
import '../ext/rrweb-snapshot/es/rrweb-snapshot.js';
import { __values } from '../ext/tslib/tslib.es6.js';
import { IGNORED_NODE, isShadowRoot, NodeType } from '../ext/rrweb-snapshot/es/rrweb-snapshot.js';
import { EventType, IncrementalSource } from './types.js';
function on(type, fn, target) {
if (target === void 0) { target = document; }
var options = { capture: true, passive: true };
target.addEventListener(type, fn, options);
return function () { return target.removeEventListener(type, fn, options); };
}
function createMirror() {
return {
map: {},
getId: function (n) {
if (!n.__sn) {
return -1;
}
return n.__sn.id;
},
getNode: function (id) {
return this.map[id] || null;
},
removeNodeFromMap: function (n) {
var _this = this;
var id = n.__sn && n.__sn.id;
delete this.map[id];
if (n.childNodes) {
n.childNodes.forEach(function (child) {
return _this.removeNodeFromMap(child);
});
}
},
has: function (id) {
return this.map.hasOwnProperty(id);
},
reset: function () {
this.map = {};
},
};
}
var DEPARTED_MIRROR_ACCESS_WARNING = 'Please stop import mirror directly. Instead of that,' +

@@ -40,3 +77,441 @@ '\r\n' +

}
function throttle(func, wait, options) {
if (options === void 0) { options = {}; }
var timeout = null;
var previous = 0;
return function (arg) {
var now = Date.now();
if (!previous && options.leading === false) {
previous = now;
}
var remaining = wait - (now - previous);
var context = this;
var args = arguments;
if (remaining <= 0 || remaining > wait) {
if (timeout) {
window.clearTimeout(timeout);
timeout = null;
}
previous = now;
func.apply(context, args);
}
else if (!timeout && options.trailing !== false) {
timeout = window.setTimeout(function () {
previous = options.leading === false ? 0 : Date.now();
timeout = null;
func.apply(context, args);
}, remaining);
}
};
}
function hookSetter(target, key, d, isRevoked, win) {
if (win === void 0) { win = window; }
var original = win.Object.getOwnPropertyDescriptor(target, key);
win.Object.defineProperty(target, key, isRevoked
? d
: {
set: function (value) {
var _this = this;
setTimeout(function () {
d.set.call(_this, value);
}, 0);
if (original && original.set) {
original.set.call(this, value);
}
},
});
return function () { return hookSetter(target, key, original || {}, true); };
}
function patch(source, name, replacement) {
try {
if (!(name in source)) {
return function () { };
}
var original_1 = source[name];
var wrapped = replacement(original_1);
if (typeof wrapped === 'function') {
wrapped.prototype = wrapped.prototype || {};
Object.defineProperties(wrapped, {
__rrweb_original__: {
enumerable: false,
value: original_1,
},
});
}
source[name] = wrapped;
return function () {
source[name] = original_1;
};
}
catch (_a) {
return function () { };
}
}
function getWindowHeight() {
return (window.innerHeight ||
(document.documentElement && document.documentElement.clientHeight) ||
(document.body && document.body.clientHeight));
}
function getWindowWidth() {
return (window.innerWidth ||
(document.documentElement && document.documentElement.clientWidth) ||
(document.body && document.body.clientWidth));
}
function isBlocked(node, blockClass) {
if (!node) {
return false;
}
if (node.nodeType === node.ELEMENT_NODE) {
var needBlock_1 = false;
if (typeof blockClass === 'string') {
needBlock_1 = node.classList.contains(blockClass);
}
else {
node.classList.forEach(function (className) {
if (blockClass.test(className)) {
needBlock_1 = true;
}
});
}
return needBlock_1 || isBlocked(node.parentNode, blockClass);
}
if (node.nodeType === node.TEXT_NODE) {
return isBlocked(node.parentNode, blockClass);
}
return isBlocked(node.parentNode, blockClass);
}
function isIgnored(n) {
if ('__sn' in n) {
return n.__sn.id === IGNORED_NODE;
}
return false;
}
function isAncestorRemoved(target, mirror) {
if (isShadowRoot(target)) {
return false;
}
var id = mirror.getId(target);
if (!mirror.has(id)) {
return true;
}
if (target.parentNode &&
target.parentNode.nodeType === target.DOCUMENT_NODE) {
return false;
}
if (!target.parentNode) {
return true;
}
return isAncestorRemoved(target.parentNode, mirror);
}
function isTouchEvent(event) {
return Boolean(event.changedTouches);
}
function polyfill(win) {
if (win === void 0) { win = window; }
if ('NodeList' in win && !win.NodeList.prototype.forEach) {
win.NodeList.prototype.forEach = Array.prototype
.forEach;
}
if ('DOMTokenList' in win && !win.DOMTokenList.prototype.forEach) {
win.DOMTokenList.prototype.forEach = Array.prototype
.forEach;
}
if (!Node.prototype.contains) {
Node.prototype.contains = function contains(node) {
if (!(0 in arguments)) {
throw new TypeError('1 argument is required');
}
do {
if (this === node) {
return true;
}
} while ((node = node && node.parentNode));
return false;
};
}
}
function needCastInSyncMode(event) {
switch (event.type) {
case EventType.DomContentLoaded:
case EventType.Load:
case EventType.Custom:
return false;
case EventType.FullSnapshot:
case EventType.Meta:
case EventType.Plugin:
return true;
}
switch (event.data.source) {
case IncrementalSource.MouseMove:
case IncrementalSource.MouseInteraction:
case IncrementalSource.TouchMove:
case IncrementalSource.MediaInteraction:
return false;
case IncrementalSource.ViewportResize:
case IncrementalSource.StyleSheetRule:
case IncrementalSource.Scroll:
case IncrementalSource.Input:
return true;
}
return true;
}
var TreeIndex = (function () {
function TreeIndex() {
this.reset();
}
TreeIndex.prototype.add = function (mutation) {
var parentTreeNode = this.indexes.get(mutation.parentId);
var treeNode = {
id: mutation.node.id,
mutation: mutation,
children: [],
texts: [],
attributes: [],
};
if (!parentTreeNode) {
this.tree[treeNode.id] = treeNode;
}
else {
treeNode.parent = parentTreeNode;
parentTreeNode.children[treeNode.id] = treeNode;
}
this.indexes.set(treeNode.id, treeNode);
};
TreeIndex.prototype.remove = function (mutation, mirror) {
var _this = this;
var parentTreeNode = this.indexes.get(mutation.parentId);
var treeNode = this.indexes.get(mutation.id);
var deepRemoveFromMirror = function (id) {
_this.removeIdSet.add(id);
var node = mirror.getNode(id);
node === null || node === void 0 ? void 0 : node.childNodes.forEach(function (childNode) {
if ('__sn' in childNode) {
deepRemoveFromMirror(childNode.__sn.id);
}
});
};
var deepRemoveFromTreeIndex = function (node) {
_this.removeIdSet.add(node.id);
Object.values(node.children).forEach(function (n) { return deepRemoveFromTreeIndex(n); });
var _treeNode = _this.indexes.get(node.id);
if (_treeNode) {
var _parentTreeNode = _treeNode.parent;
if (_parentTreeNode) {
delete _treeNode.parent;
delete _parentTreeNode.children[_treeNode.id];
_this.indexes.delete(mutation.id);
}
}
};
if (!treeNode) {
this.removeNodeMutations.push(mutation);
deepRemoveFromMirror(mutation.id);
}
else if (!parentTreeNode) {
delete this.tree[treeNode.id];
this.indexes.delete(treeNode.id);
deepRemoveFromTreeIndex(treeNode);
}
else {
delete treeNode.parent;
delete parentTreeNode.children[treeNode.id];
this.indexes.delete(mutation.id);
deepRemoveFromTreeIndex(treeNode);
}
};
TreeIndex.prototype.text = function (mutation) {
var treeNode = this.indexes.get(mutation.id);
if (treeNode) {
treeNode.texts.push(mutation);
}
else {
this.textMutations.push(mutation);
}
};
TreeIndex.prototype.attribute = function (mutation) {
var treeNode = this.indexes.get(mutation.id);
if (treeNode) {
treeNode.attributes.push(mutation);
}
else {
this.attributeMutations.push(mutation);
}
};
TreeIndex.prototype.scroll = function (d) {
this.scrollMap.set(d.id, d);
};
TreeIndex.prototype.input = function (d) {
this.inputMap.set(d.id, d);
};
TreeIndex.prototype.flush = function () {
var e_1, _a, e_2, _b;
var _this = this;
var _c = this, tree = _c.tree, removeNodeMutations = _c.removeNodeMutations, textMutations = _c.textMutations, attributeMutations = _c.attributeMutations;
var batchMutationData = {
source: IncrementalSource.Mutation,
removes: removeNodeMutations,
texts: textMutations,
attributes: attributeMutations,
adds: [],
};
var walk = function (treeNode, removed) {
if (removed) {
_this.removeIdSet.add(treeNode.id);
}
batchMutationData.texts = batchMutationData.texts
.concat(removed ? [] : treeNode.texts)
.filter(function (m) { return !_this.removeIdSet.has(m.id); });
batchMutationData.attributes = batchMutationData.attributes
.concat(removed ? [] : treeNode.attributes)
.filter(function (m) { return !_this.removeIdSet.has(m.id); });
if (!_this.removeIdSet.has(treeNode.id) &&
!_this.removeIdSet.has(treeNode.mutation.parentId) &&
!removed) {
batchMutationData.adds.push(treeNode.mutation);
if (treeNode.children) {
Object.values(treeNode.children).forEach(function (n) { return walk(n, false); });
}
}
else {
Object.values(treeNode.children).forEach(function (n) { return walk(n, true); });
}
};
Object.values(tree).forEach(function (n) { return walk(n, false); });
try {
for (var _d = __values(this.scrollMap.keys()), _e = _d.next(); !_e.done; _e = _d.next()) {
var id = _e.value;
if (this.removeIdSet.has(id)) {
this.scrollMap.delete(id);
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
}
finally { if (e_1) throw e_1.error; }
}
try {
for (var _f = __values(this.inputMap.keys()), _g = _f.next(); !_g.done; _g = _f.next()) {
var id = _g.value;
if (this.removeIdSet.has(id)) {
this.inputMap.delete(id);
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
}
finally { if (e_2) throw e_2.error; }
}
var scrollMap = new Map(this.scrollMap);
var inputMap = new Map(this.inputMap);
this.reset();
return {
mutationData: batchMutationData,
scrollMap: scrollMap,
inputMap: inputMap,
};
};
TreeIndex.prototype.reset = function () {
this.tree = [];
this.indexes = new Map();
this.removeNodeMutations = [];
this.textMutations = [];
this.attributeMutations = [];
this.removeIdSet = new Set();
this.scrollMap = new Map();
this.inputMap = new Map();
};
return TreeIndex;
}());
function queueToResolveTrees(queue) {
var e_3, _a;
var queueNodeMap = {};
var putIntoMap = function (m, parent) {
var nodeInTree = {
value: m,
parent: parent,
children: [],
};
queueNodeMap[m.node.id] = nodeInTree;
return nodeInTree;
};
var queueNodeTrees = [];
try {
for (var queue_1 = __values(queue), queue_1_1 = queue_1.next(); !queue_1_1.done; queue_1_1 = queue_1.next()) {
var mutation = queue_1_1.value;
var nextId = mutation.nextId, parentId = mutation.parentId;
if (nextId && nextId in queueNodeMap) {
var nextInTree = queueNodeMap[nextId];
if (nextInTree.parent) {
var idx = nextInTree.parent.children.indexOf(nextInTree);
nextInTree.parent.children.splice(idx, 0, putIntoMap(mutation, nextInTree.parent));
}
else {
var idx = queueNodeTrees.indexOf(nextInTree);
queueNodeTrees.splice(idx, 0, putIntoMap(mutation, null));
}
continue;
}
if (parentId in queueNodeMap) {
var parentInTree = queueNodeMap[parentId];
parentInTree.children.push(putIntoMap(mutation, parentInTree));
continue;
}
queueNodeTrees.push(putIntoMap(mutation, null));
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (queue_1_1 && !queue_1_1.done && (_a = queue_1.return)) _a.call(queue_1);
}
finally { if (e_3) throw e_3.error; }
}
return queueNodeTrees;
}
function iterateResolveTree(tree, cb) {
cb(tree.value);
for (var i = tree.children.length - 1; i >= 0; i--) {
iterateResolveTree(tree.children[i], cb);
}
}
function isIframeINode(node) {
if ('__sn' in node) {
return (node.__sn.type === NodeType.Element && node.__sn.tagName === 'iframe');
}
return false;
}
function getBaseDimension(node, rootIframe) {
var _a, _b;
var frameElement = (_b = (_a = node.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) === null || _b === void 0 ? void 0 : _b.frameElement;
if (!frameElement || frameElement === rootIframe) {
return {
x: 0,
y: 0,
relativeScale: 1,
absoluteScale: 1,
};
}
var frameDimension = frameElement.getBoundingClientRect();
var frameBaseDimension = getBaseDimension(frameElement, rootIframe);
var relativeScale = frameDimension.height / frameElement.clientHeight;
return {
x: frameDimension.x * frameBaseDimension.relativeScale +
frameBaseDimension.x,
y: frameDimension.y * frameBaseDimension.relativeScale +
frameBaseDimension.y,
relativeScale: relativeScale,
absoluteScale: frameBaseDimension.absoluteScale * relativeScale,
};
}
function hasShadowRoot(n) {
var _a;
return Boolean((_a = n) === null || _a === void 0 ? void 0 : _a.shadowRoot);
}
export { _mirror };
export { TreeIndex, _mirror, createMirror, getBaseDimension, getWindowHeight, getWindowWidth, hasShadowRoot, hookSetter, isAncestorRemoved, isBlocked, isIframeINode, isIgnored, isTouchEvent, iterateResolveTree, needCastInSyncMode, on, patch, polyfill, queueToResolveTrees, throttle };

@@ -246,3 +246,3 @@ 'use strict';

}());
var getLogReplayPlugin = function (options) {
var getReplayConsolePlugin = function (options) {
var replayLogger = (options === null || options === void 0 ? void 0 : options.replayLogger) || new LogReplayPlugin(options).getConsoleLogger();

@@ -276,2 +276,2 @@ return {

exports.getLogReplayPlugin = getLogReplayPlugin;
exports.getReplayConsolePlugin = getReplayConsolePlugin;
{
"name": "rrweb",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "record and replay the web",

@@ -5,0 +5,0 @@ "scripts": {

@@ -8,3 +8,3 @@ import { LogLevel, LogData } from '../record';

};
export declare const getLogReplayPlugin: (options?: LogReplayConfig) => ReplayPlugin;
export declare const getReplayConsolePlugin: (options?: LogReplayConfig) => ReplayPlugin;
export {};

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 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc