@openreplay/tracker
Advanced tools
Comparing version 3.5.3 to 3.5.4
@@ -15,3 +15,3 @@ "use strict"; | ||
doc.defaultView; // TODO: smart global typing for Window object | ||
while (context.parent && context.parent !== context) { | ||
while ((context.parent || context.top) && context.parent !== context) { | ||
// @ts-ignore | ||
@@ -22,3 +22,3 @@ if (node instanceof context[constr.name]) { | ||
// @ts-ignore | ||
context = context.parent; | ||
context = context.parent || context.top; | ||
} | ||
@@ -29,20 +29,19 @@ // @ts-ignore | ||
exports.isInstance = isInstance; | ||
// TODO: ensure 1. it works in every cases (iframes/detached nodes) and 2. the most efficient | ||
function inDocument(node) { | ||
const doc = node.ownerDocument; | ||
if (!doc) { | ||
return false; | ||
} | ||
if (doc.contains(node)) { | ||
return true; | ||
} | ||
let context = | ||
// @ts-ignore (for EI, Safary) | ||
doc.parentWindow || | ||
doc.defaultView; | ||
while (context.parent && context.parent !== context) { | ||
if (context.document.contains(node)) { | ||
} // Document | ||
let current = node; | ||
while (current) { | ||
if (current === doc) { | ||
return true; | ||
} | ||
// @ts-ignore | ||
context = context.parent; | ||
else if (isInstance(current, ShadowRoot)) { | ||
current = current.host; | ||
} | ||
else { | ||
current = current.parentNode; | ||
} | ||
} | ||
@@ -52,1 +51,25 @@ return false; | ||
exports.inDocument = inDocument; | ||
// export function inDocument(node: Node): boolean { | ||
// // @ts-ignore compatability | ||
// if (node.getRootNode) { | ||
// let root: Node | ||
// while ((root = node.getRootNode()) !== node) { | ||
// //// | ||
// } | ||
// } | ||
// const doc = node.ownerDocument | ||
// if (!doc) { return false } | ||
// if (doc.contains(node)) { return true } | ||
// let context: Window = | ||
// // @ts-ignore (for EI, Safary) | ||
// doc.parentWindow || | ||
// doc.defaultView; | ||
// while(context.parent && context.parent !== context) { | ||
// if (context.document.contains(node)) { | ||
// return true | ||
// } | ||
// // @ts-ignore | ||
// context = context.parent | ||
// } | ||
// return false; | ||
// } |
@@ -32,3 +32,3 @@ "use strict"; | ||
this.activityState = ActivityState.NotActive; | ||
this.version = '3.5.3'; // TODO: version compatability check inside each plugin. | ||
this.version = '3.5.4'; // TODO: version compatability check inside each plugin. | ||
this.preStartMessages = []; | ||
@@ -35,0 +35,0 @@ this.projectKey = projectKey; |
import App from "../index.js"; | ||
export default abstract class Observer { | ||
protected readonly app: App; | ||
protected readonly context: Window; | ||
protected readonly isTopContext: boolean; | ||
private readonly observer; | ||
@@ -12,4 +12,3 @@ private readonly commited; | ||
private readonly textSet; | ||
private readonly inUpperContext; | ||
constructor(app: App, context?: Window); | ||
constructor(app: App, isTopContext?: boolean); | ||
private clear; | ||
@@ -16,0 +15,0 @@ private sendNodeAttribute; |
@@ -37,5 +37,5 @@ "use strict"; | ||
class Observer { | ||
constructor(app, context = window) { | ||
constructor(app, isTopContext = false) { | ||
this.app = app; | ||
this.context = context; | ||
this.isTopContext = isTopContext; | ||
this.commited = []; | ||
@@ -47,3 +47,2 @@ this.recents = []; | ||
this.textSet = new Set(); | ||
this.inUpperContext = context.parent === context; //TODO: get rid of context here | ||
this.observer = new MutationObserver(this.app.safe((mutations) => { | ||
@@ -191,3 +190,3 @@ for (const mutation of mutations) { | ||
// TODO: Clean the logic (though now it workd fine) | ||
if (!(0, context_js_1.isInstance)(node, HTMLHtmlElement) || !this.inUpperContext) { | ||
if (!(0, context_js_1.isInstance)(node, HTMLHtmlElement) || !this.isTopContext) { | ||
if (parent === null) { | ||
@@ -280,2 +279,4 @@ this.unbindNode(node); | ||
// commit required in any case if recents[id] true or false (in case of unbinding) or undefined (in case of attr change). | ||
// Possible solution: separate new node commit (recents) and new attribute/move node commit | ||
// Otherwise commitNode is called on each node, which might be a lot | ||
if (!this.myNodes[id]) { | ||
@@ -282,0 +283,0 @@ continue; |
@@ -12,7 +12,7 @@ "use strict"; | ||
constructor(app, options) { | ||
super(app); | ||
super(app, true); | ||
this.iframeObservers = []; | ||
this.shadowRootObservers = []; | ||
this.options = Object.assign({ | ||
captureIFrames: false | ||
captureIFrames: true | ||
}, options); | ||
@@ -22,3 +22,4 @@ // IFrames | ||
if ((0, context_js_1.isInstance)(node, HTMLIFrameElement) && | ||
(this.options.captureIFrames || node.getAttribute("data-openreplay-capture"))) { | ||
((this.options.captureIFrames && !(0, utils_js_1.hasOpenreplayAttribute)(node, "obscured")) | ||
|| (0, utils_js_1.hasOpenreplayAttribute)(node, "capture"))) { | ||
this.handleIframe(node); | ||
@@ -35,3 +36,3 @@ } | ||
handleIframe(iframe) { | ||
let context = null; | ||
let doc = null; | ||
const handle = this.app.safe(() => { | ||
@@ -42,18 +43,18 @@ const id = this.app.nodes.getID(iframe); | ||
} //log | ||
if (iframe.contentWindow === context) { | ||
if (iframe.contentDocument === doc) { | ||
return; | ||
} //Does this happen frequently? | ||
context = iframe.contentWindow; | ||
if (!context) { | ||
} // How frequently can it happen? | ||
doc = iframe.contentDocument; | ||
if (!doc || !iframe.contentWindow) { | ||
return; | ||
} | ||
const observer = new iframe_observer_js_1.default(this.app, context); | ||
const observer = new iframe_observer_js_1.default(this.app); | ||
this.iframeObservers.push(observer); | ||
observer.observe(iframe); | ||
}); | ||
this.app.attachEventListener(iframe, "load", handle); | ||
iframe.addEventListener("load", handle); // why app.attachEventListener not working? | ||
handle(); | ||
} | ||
handleShadowRoot(shRoot) { | ||
const observer = new shadow_root_observer_js_1.default(this.app, this.context); | ||
const observer = new shadow_root_observer_js_1.default(this.app); | ||
this.shadowRootObservers.push(observer); | ||
@@ -76,5 +77,5 @@ observer.observe(shRoot.host); | ||
// Alternatively - observe(#document) then bindNode(documentElement) | ||
this.observeRoot(this.context.document, () => { | ||
this.observeRoot(window.document, () => { | ||
this.app.send(new index_js_1.CreateDocument()); | ||
}, this.context.document.documentElement); | ||
}, window.document.documentElement); | ||
} | ||
@@ -81,0 +82,0 @@ disconnect() { |
@@ -130,3 +130,3 @@ "use strict"; | ||
req.send(JSON.stringify({ | ||
trackerVersion: '3.5.3', | ||
trackerVersion: '3.5.4', | ||
projectKey: options.projectKey, | ||
@@ -133,0 +133,0 @@ doNotTrack, |
@@ -12,3 +12,3 @@ // TODO: we need a type expert here so we won't have to ignore the lines | ||
doc.defaultView; // TODO: smart global typing for Window object | ||
while (context.parent && context.parent !== context) { | ||
while ((context.parent || context.top) && context.parent !== context) { | ||
// @ts-ignore | ||
@@ -19,3 +19,3 @@ if (node instanceof context[constr.name]) { | ||
// @ts-ignore | ||
context = context.parent; | ||
context = context.parent || context.top; | ||
} | ||
@@ -25,22 +25,45 @@ // @ts-ignore | ||
} | ||
// TODO: ensure 1. it works in every cases (iframes/detached nodes) and 2. the most efficient | ||
export function inDocument(node) { | ||
const doc = node.ownerDocument; | ||
if (!doc) { | ||
return false; | ||
} | ||
if (doc.contains(node)) { | ||
return true; | ||
} | ||
let context = | ||
// @ts-ignore (for EI, Safary) | ||
doc.parentWindow || | ||
doc.defaultView; | ||
while (context.parent && context.parent !== context) { | ||
if (context.document.contains(node)) { | ||
} // Document | ||
let current = node; | ||
while (current) { | ||
if (current === doc) { | ||
return true; | ||
} | ||
// @ts-ignore | ||
context = context.parent; | ||
else if (isInstance(current, ShadowRoot)) { | ||
current = current.host; | ||
} | ||
else { | ||
current = current.parentNode; | ||
} | ||
} | ||
return false; | ||
} | ||
// export function inDocument(node: Node): boolean { | ||
// // @ts-ignore compatability | ||
// if (node.getRootNode) { | ||
// let root: Node | ||
// while ((root = node.getRootNode()) !== node) { | ||
// //// | ||
// } | ||
// } | ||
// const doc = node.ownerDocument | ||
// if (!doc) { return false } | ||
// if (doc.contains(node)) { return true } | ||
// let context: Window = | ||
// // @ts-ignore (for EI, Safary) | ||
// doc.parentWindow || | ||
// doc.defaultView; | ||
// while(context.parent && context.parent !== context) { | ||
// if (context.document.contains(node)) { | ||
// return true | ||
// } | ||
// // @ts-ignore | ||
// context = context.parent | ||
// } | ||
// return false; | ||
// } |
@@ -29,3 +29,3 @@ import { timestamp } from "../utils.js"; | ||
this.activityState = ActivityState.NotActive; | ||
this.version = '3.5.3'; // TODO: version compatability check inside each plugin. | ||
this.version = '3.5.4'; // TODO: version compatability check inside each plugin. | ||
this.preStartMessages = []; | ||
@@ -32,0 +32,0 @@ this.projectKey = projectKey; |
import App from "../index.js"; | ||
export default abstract class Observer { | ||
protected readonly app: App; | ||
protected readonly context: Window; | ||
protected readonly isTopContext: boolean; | ||
private readonly observer; | ||
@@ -12,4 +12,3 @@ private readonly commited; | ||
private readonly textSet; | ||
private readonly inUpperContext; | ||
constructor(app: App, context?: Window); | ||
constructor(app: App, isTopContext?: boolean); | ||
private clear; | ||
@@ -16,0 +15,0 @@ private sendNodeAttribute; |
@@ -35,5 +35,5 @@ import { RemoveNodeAttribute, SetNodeAttribute, SetNodeAttributeURLBased, SetCSSDataURLBased, SetNodeData, CreateTextNode, CreateElementNode, MoveNode, RemoveNode, } from "../../messages/index.js"; | ||
export default class Observer { | ||
constructor(app, context = window) { | ||
constructor(app, isTopContext = false) { | ||
this.app = app; | ||
this.context = context; | ||
this.isTopContext = isTopContext; | ||
this.commited = []; | ||
@@ -45,3 +45,2 @@ this.recents = []; | ||
this.textSet = new Set(); | ||
this.inUpperContext = context.parent === context; //TODO: get rid of context here | ||
this.observer = new MutationObserver(this.app.safe((mutations) => { | ||
@@ -189,3 +188,3 @@ for (const mutation of mutations) { | ||
// TODO: Clean the logic (though now it workd fine) | ||
if (!isInstance(node, HTMLHtmlElement) || !this.inUpperContext) { | ||
if (!isInstance(node, HTMLHtmlElement) || !this.isTopContext) { | ||
if (parent === null) { | ||
@@ -278,2 +277,4 @@ this.unbindNode(node); | ||
// commit required in any case if recents[id] true or false (in case of unbinding) or undefined (in case of attr change). | ||
// Possible solution: separate new node commit (recents) and new attribute/move node commit | ||
// Otherwise commitNode is called on each node, which might be a lot | ||
if (!this.myNodes[id]) { | ||
@@ -280,0 +281,0 @@ continue; |
@@ -6,11 +6,11 @@ import Observer from "./observer.js"; | ||
import { CreateDocument } from "../../messages/index.js"; | ||
import { IN_BROWSER } from '../../utils.js'; | ||
import { IN_BROWSER, hasOpenreplayAttribute } from '../../utils.js'; | ||
const attachShadowNativeFn = IN_BROWSER ? Element.prototype.attachShadow : () => new ShadowRoot(); | ||
export default class TopObserver extends Observer { | ||
constructor(app, options) { | ||
super(app); | ||
super(app, true); | ||
this.iframeObservers = []; | ||
this.shadowRootObservers = []; | ||
this.options = Object.assign({ | ||
captureIFrames: false | ||
captureIFrames: true | ||
}, options); | ||
@@ -20,3 +20,4 @@ // IFrames | ||
if (isInstance(node, HTMLIFrameElement) && | ||
(this.options.captureIFrames || node.getAttribute("data-openreplay-capture"))) { | ||
((this.options.captureIFrames && !hasOpenreplayAttribute(node, "obscured")) | ||
|| hasOpenreplayAttribute(node, "capture"))) { | ||
this.handleIframe(node); | ||
@@ -33,3 +34,3 @@ } | ||
handleIframe(iframe) { | ||
let context = null; | ||
let doc = null; | ||
const handle = this.app.safe(() => { | ||
@@ -40,18 +41,18 @@ const id = this.app.nodes.getID(iframe); | ||
} //log | ||
if (iframe.contentWindow === context) { | ||
if (iframe.contentDocument === doc) { | ||
return; | ||
} //Does this happen frequently? | ||
context = iframe.contentWindow; | ||
if (!context) { | ||
} // How frequently can it happen? | ||
doc = iframe.contentDocument; | ||
if (!doc || !iframe.contentWindow) { | ||
return; | ||
} | ||
const observer = new IFrameObserver(this.app, context); | ||
const observer = new IFrameObserver(this.app); | ||
this.iframeObservers.push(observer); | ||
observer.observe(iframe); | ||
}); | ||
this.app.attachEventListener(iframe, "load", handle); | ||
iframe.addEventListener("load", handle); // why app.attachEventListener not working? | ||
handle(); | ||
} | ||
handleShadowRoot(shRoot) { | ||
const observer = new ShadowRootObserver(this.app, this.context); | ||
const observer = new ShadowRootObserver(this.app); | ||
this.shadowRootObservers.push(observer); | ||
@@ -74,5 +75,5 @@ observer.observe(shRoot.host); | ||
// Alternatively - observe(#document) then bindNode(documentElement) | ||
this.observeRoot(this.context.document, () => { | ||
this.observeRoot(window.document, () => { | ||
this.app.send(new CreateDocument()); | ||
}, this.context.document.documentElement); | ||
}, window.document.documentElement); | ||
} | ||
@@ -79,0 +80,0 @@ disconnect() { |
@@ -126,3 +126,3 @@ import App, { DEFAULT_INGEST_POINT } from "./app/index.js"; | ||
req.send(JSON.stringify({ | ||
trackerVersion: '3.5.3', | ||
trackerVersion: '3.5.4', | ||
projectKey: options.projectKey, | ||
@@ -129,0 +129,0 @@ doNotTrack, |
{ | ||
"name": "@openreplay/tracker", | ||
"description": "The OpenReplay tracker main package", | ||
"version": "3.5.3", | ||
"version": "3.5.4", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "logging", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
359928
9046