How to use rrweb-snapshot - 6 common examples

To help you get started, we’ve selected a few rrweb-snapshot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rrweb-io / rrweb / src / record / observer.ts View on Github external
const value = (target as HTMLElement).getAttribute(attributeName!);
          if (isBlocked(target, blockClass) || value === oldValue) {
            return;
          }
          let item: attributeCursor | undefined = attributes.find(
            a => a.node === target,
          );
          if (!item) {
            item = {
              node: target,
              attributes: {},
            };
            attributes.push(item);
          }
          // overwrite attribute if the mutations was triggered in same time
          item.attributes[attributeName!] = transformAttribute(
            document,
            attributeName!,
            value!,
          );
          break;
        }
        case 'childList': {
          addedNodes.forEach(n => genAdds(n, target));
          removedNodes.forEach(n => {
            const nodeId = mirror.getId(n as INode);
            const parentId = mirror.getId(target as INode);
            if (isBlocked(n, blockClass)) {
              return;
            }
            // removed node has not been serialized yet, just remove it from the Set
            if (addedSet.has(n)) {
github rrweb-io / rrweb / test / integration.ts View on Github external
s.data.adds.forEach(add => {
            if (
              add.node.type === NodeType.Element &&
              'style' in add.node.attributes &&
              typeof add.node.attributes.style === 'string' &&
              coordinatesReg.test(add.node.attributes.style)
            ) {
              delete add.node.attributes.style;
            }
          });
        }
github rrweb-io / rrweb / src / replay / index.ts View on Github external
private rebuildFullSnapshot(
    event: fullSnapshotEvent & { timestamp: number },
  ) {
    if (Object.keys(this.missingNodeRetryMap).length) {
      console.warn(
        'Found unresolved missing node map',
        this.missingNodeRetryMap,
      );
    }
    this.missingNodeRetryMap = {};
    mirror.map = rebuild(event.data.node, this.iframe.contentDocument!)[1];
    const styleEl = document.createElement('style');
    const { documentElement, head } = this.iframe.contentDocument!;
    documentElement!.insertBefore(styleEl, head);
    const injectStylesRules = getInjectStyleRules(
      this.config.blockClass,
    ).concat(this.config.insertStyleRules);
    for (let idx = 0; idx < injectStylesRules.length; idx++) {
      (styleEl.sheet! as CSSStyleSheet).insertRule(injectStylesRules[idx], idx);
    }
    this.emitter.emit(ReplayerEvents.FullsnapshotRebuilded);
    this.waitForStylesheetLoad();
  }
github rrweb-io / rrweb / src / record / index.ts View on Github external
function takeFullSnapshot(isCheckout = false) {
    wrappedEmit(
      wrapEvent({
        type: EventType.Meta,
        data: {
          href: window.location.href,
          width: getWindowWidth(),
          height: getWindowHeight(),
        },
      }),
      isCheckout,
    );
    const [node, idNodeMap] = snapshot(
      document,
      blockClass,
      inlineStylesheet,
      maskAllInputs,
    );
    if (!node) {
      return console.warn('Failed to snapshot the document');
    }
    mirror.map = idNodeMap;
    wrappedEmit(
      wrapEvent({
        type: EventType.FullSnapshot,
        data: {
          node,
          initialOffset: {
            left: document.documentElement!.scrollLeft,
github rrweb-io / rrweb / src / record / observer.ts View on Github external
const pushAdd = (n: Node) => {
      const parentId = mirror.getId((n.parentNode as Node) as INode);
      if (parentId === -1) {
        return addQueue.push(n);
      }
      adds.push({
        parentId,
        previousId: !n.previousSibling
          ? n.previousSibling
          : mirror.getId(n.previousSibling as INode),
        nextId: !n.nextSibling
          ? n.nextSibling
          : mirror.getId((n.nextSibling as unknown) as INode),
        node: serializeNodeWithId(
          n,
          document,
          mirror.map,
          blockClass,
          true,
          inlineStylesheet,
          maskAllInputs,
        )!,
      });
    };
github rrweb-io / rrweb / src / replay / index.ts View on Github external
const appendNode = (mutation: addedNodeMutation) => {
          const parent = mirror.getNode(mutation.parentId);
          if (!parent) {
            return queue.push(mutation);
          }
          const target = buildNodeWithSN(
            mutation.node,
            this.iframe.contentDocument!,
            mirror.map,
            true,
          ) as Node;
          let previous: Node | null = null;
          let next: Node | null = null;
          if (mutation.previousId) {
            previous = mirror.getNode(mutation.previousId) as Node;
          }
          if (mutation.nextId) {
            next = mirror.getNode(mutation.nextId) as Node;
          }

          if (mutation.previousId === -1 || mutation.nextId === -1) {
            missingNodeMap[mutation.node.id] = {

rrweb-snapshot

rrweb's component to take a snapshot of DOM, aka DOM serializer

MIT
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis