@openreplay/tracker 3.4.9 → 3.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ import Observer from "./observer.js";
2
+ import type { Options as BaseOptions } from "./observer.js";
3
+ import App from "../index.js";
4
+ export interface Options extends Partial<BaseOptions> {
5
+ captureIFrames: boolean;
6
+ }
7
+ export default class TopObserver extends Observer<Options> {
8
+ constructor(app: App, options: Partial<Options>);
9
+ private iframeObservers;
10
+ private handleIframe;
11
+ private shadowRootObservers;
12
+ private handleShadowRoot;
13
+ observe(): void;
14
+ disconnect(): void;
15
+ }
@@ -0,0 +1,79 @@
1
+ import Observer, { isInstance } from "./observer.js";
2
+ import IFrameObserver from "./iframe_observer.js";
3
+ import ShadowRootObserver from "./shadow_root_observer.js";
4
+ import { CreateDocument } from "../../messages/index.js";
5
+ const attachShadowNativeFn = Element.prototype.attachShadow;
6
+ export default class TopObserver extends Observer {
7
+ constructor(app, options) {
8
+ super(app, Object.assign({
9
+ captureIFrames: false
10
+ }, options));
11
+ this.iframeObservers = [];
12
+ this.shadowRootObservers = [];
13
+ // IFrames
14
+ this.app.nodes.attachNodeCallback(node => {
15
+ if (isInstance(node, HTMLIFrameElement) &&
16
+ (this.options.captureIFrames || node.getAttribute("data-openreplay-capture"))) {
17
+ this.handleIframe(node);
18
+ }
19
+ });
20
+ // ShadowDOM
21
+ this.app.nodes.attachNodeCallback(node => {
22
+ if (isInstance(node, Element) && node.shadowRoot !== null) {
23
+ this.handleShadowRoot(node.shadowRoot);
24
+ }
25
+ });
26
+ }
27
+ handleIframe(iframe) {
28
+ let context = null;
29
+ const handle = this.app.safe(() => {
30
+ const id = this.app.nodes.getID(iframe);
31
+ if (id === undefined) {
32
+ return;
33
+ } //log
34
+ if (iframe.contentWindow === context) {
35
+ return;
36
+ } //Does this happen frequently?
37
+ context = iframe.contentWindow;
38
+ if (!context) {
39
+ return;
40
+ }
41
+ const observer = new IFrameObserver(this.app, this.options, context);
42
+ this.iframeObservers.push(observer);
43
+ observer.observe(iframe);
44
+ });
45
+ this.app.attachEventListener(iframe, "load", handle);
46
+ handle();
47
+ }
48
+ handleShadowRoot(shRoot) {
49
+ const observer = new ShadowRootObserver(this.app, this.options, this.context);
50
+ this.shadowRootObservers.push(observer);
51
+ observer.observe(shRoot.host);
52
+ }
53
+ observe() {
54
+ // Protection from several subsequent calls?
55
+ const observer = this;
56
+ Element.prototype.attachShadow = function () {
57
+ const shadow = attachShadowNativeFn.apply(this, arguments);
58
+ observer.handleShadowRoot(shadow);
59
+ return shadow;
60
+ };
61
+ // Can observe documentElement (<html>) here, because it is not supposed to be changing.
62
+ // However, it is possible in some exotic cases and may cause an ignorance of the newly created <html>
63
+ // In this case context.document have to be observed, but this will cause
64
+ // the change in the re-player behaviour caused by CreateDocument message:
65
+ // the 0-node ("fRoot") will become #document rather than documentElement as it is now.
66
+ // Alternatively - observe(#document) then bindNode(documentElement)
67
+ this.observeRoot(this.context.document, () => {
68
+ this.app.send(new CreateDocument());
69
+ }, this.context.document.documentElement);
70
+ }
71
+ disconnect() {
72
+ Element.prototype.attachShadow = attachShadowNativeFn;
73
+ this.iframeObservers.forEach(o => o.disconnect());
74
+ this.iframeObservers = [];
75
+ this.shadowRootObservers.forEach(o => o.disconnect());
76
+ this.shadowRootObservers = [];
77
+ super.disconnect();
78
+ }
79
+ }
File without changes
@@ -0,0 +1 @@
1
+ "use strict";
package/lib/index.js CHANGED
@@ -111,7 +111,7 @@ export default class API {
111
111
  // no-cors issue only with text/plain or not-set Content-Type
112
112
  // req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
113
113
  req.send(JSON.stringify({
114
- trackerVersion: '3.4.9',
114
+ trackerVersion: '3.4.10',
115
115
  projectKey: options.projectKey,
116
116
  doNotTrack,
117
117
  // TODO: add precise reason (an exact API missing)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openreplay/tracker",
3
3
  "description": "The OpenReplay tracker main package",
4
- "version": "3.4.9",
4
+ "version": "3.4.10",
5
5
  "keywords": [
6
6
  "logging",
7
7
  "replay"