@openreplay/tracker 4.1.4-beta → 4.1.4-beta.0

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.
@@ -28,12 +28,12 @@ function default_1(app) {
28
28
  }
29
29
  const styleSheetIDMap = new Map();
30
30
  const adoptedStyleSheetsOwnings = new Map();
31
- const sendAdoptedStyleSheetsUpdate = (root) => {
31
+ const sendAdoptedStyleSheetsUpdate = (root) => setTimeout(() => {
32
32
  let nodeID = app.nodes.getID(root);
33
33
  if (root === document) {
34
34
  nodeID = 0; // main document doesn't have nodeID. ID count starts from the documentElement
35
35
  }
36
- if (!nodeID) {
36
+ if (nodeID === undefined) {
37
37
  return;
38
38
  }
39
39
  let pastOwning = adoptedStyleSheetsOwnings.get(nodeID);
@@ -48,28 +48,31 @@ function default_1(app) {
48
48
  if (!sheetID) {
49
49
  sheetID = nextID();
50
50
  }
51
- nowOwning.push(sheetID);
52
51
  if (!pastOwning.includes(sheetID)) {
53
52
  app.send((0, messages_gen_js_1.AdoptedSSAddOwner)(sheetID, nodeID));
54
53
  }
55
54
  if (init) {
56
55
  const rules = s.cssRules;
57
56
  for (let i = 0; i < rules.length; i++) {
57
+ nodeID === 1110 && console.log(rules[i].cssText, root, s, root.adoptedStyleSheets[0], s.cssRules[0]);
58
58
  app.send((0, messages_gen_js_1.AdoptedSSInsertRuleURLBased)(sheetID, rules[i].cssText, i, app.getBaseHref()));
59
59
  }
60
60
  }
61
+ nowOwning.push(sheetID);
61
62
  }
63
+ // nodeID === 0 && console.log(pastOwning, nowOwning, nowOwning.length)
62
64
  for (const sheetID of pastOwning) {
63
65
  if (!nowOwning.includes(sheetID)) {
64
66
  app.send((0, messages_gen_js_1.AdoptedSSRemoveOwner)(sheetID, nodeID));
65
67
  }
66
68
  }
67
69
  adoptedStyleSheetsOwnings.set(nodeID, nowOwning);
68
- };
69
- function patchAdoptedStyleSheets(prototype) {
70
+ }, 0);
71
+ function patchAdoptedStyleSheets(prototype, ctx) {
70
72
  const nativeAdoptedStyleSheetsDescriptor = Object.getOwnPropertyDescriptor(prototype, 'adoptedStyleSheets');
71
73
  if (nativeAdoptedStyleSheetsDescriptor) {
72
74
  Object.defineProperty(prototype, 'adoptedStyleSheets', Object.assign(Object.assign({}, nativeAdoptedStyleSheetsDescriptor), { set: function (value) {
75
+ ctx !== window && ctx.Document.prototype === prototype && console.log("custom set!", value, ctx);
73
76
  // @ts-ignore
74
77
  const retVal = nativeAdoptedStyleSheetsDescriptor.set.call(this, value);
75
78
  sendAdoptedStyleSheetsUpdate(this);
@@ -78,6 +81,8 @@ function default_1(app) {
78
81
  }
79
82
  }
80
83
  const patchContext = (context) => {
84
+ // @ts-ignore
85
+ console.log("new context", context, context.document.adoptedStyleSheets.length && context.document.adoptedStyleSheets[0].cssRules[0].cssText);
81
86
  // @ts-ignore
82
87
  if (context.__openreplay_adpss_patched__) {
83
88
  return;
@@ -86,12 +91,13 @@ function default_1(app) {
86
91
  // @ts-ignore
87
92
  context.__openreplay_adpss_patched__ = true;
88
93
  }
89
- patchAdoptedStyleSheets(context.Document.prototype);
90
- patchAdoptedStyleSheets(context.ShadowRoot.prototype);
94
+ patchAdoptedStyleSheets(context.Document.prototype, context);
95
+ patchAdoptedStyleSheets(context.ShadowRoot.prototype, context);
91
96
  //@ts-ignore TODO: configure ts (use necessary lib)
92
- const { insertRule, deleteRule, replace, replaceSync } = context.CSSStyleSheet.prototype;
97
+ const { replace, replaceSync } = context.CSSStyleSheet.prototype;
93
98
  //@ts-ignore
94
99
  context.CSSStyleSheet.prototype.replace = function (text) {
100
+ styleSheetIDMap.get(this) === 102 && console.log("replace with", text);
95
101
  return replace.call(this, text).then((sheet) => {
96
102
  const sheetID = styleSheetIDMap.get(this);
97
103
  if (sheetID) {
@@ -103,6 +109,7 @@ function default_1(app) {
103
109
  //@ts-ignore
104
110
  context.CSSStyleSheet.prototype.replaceSync = function (text) {
105
111
  const sheetID = styleSheetIDMap.get(this);
112
+ sheetID === 102 && console.log("replacesnc with", text);
106
113
  if (sheetID) {
107
114
  app.send((0, messages_gen_js_1.AdoptedSSReplaceURLBased)(sheetID, text, app.getBaseHref()));
108
115
  }
@@ -110,7 +117,7 @@ function default_1(app) {
110
117
  };
111
118
  };
112
119
  patchContext(window);
113
- app.observer.attachContextCallback(patchContext);
120
+ app.observer.attachContextCallback(app.safe(patchContext));
114
121
  app.attachStopCallback(() => {
115
122
  styleSheetIDMap.clear();
116
123
  adoptedStyleSheetsOwnings.clear();
@@ -11,7 +11,7 @@ function default_1(app) {
11
11
  app.send((0, messages_gen_js_1.TechnicalInfo)('no_stylesheet_prototype_in_window', ''));
12
12
  return;
13
13
  }
14
- const sendInserDeleteRule = app.safe((sheet, index, rule) => {
14
+ const sendInsertDeleteRule = app.safe((sheet, index, rule) => {
15
15
  const sheetID = constructedStyleSheets_js_1.styleSheetIDMap.get(sheet);
16
16
  if (!sheetID) {
17
17
  // OK-case. Sheet haven't been registered yet. Rules will be sent on registration.
@@ -51,15 +51,15 @@ function default_1(app) {
51
51
  app.debug.warn('Rule index not found in', sheet, topmostRule);
52
52
  }
53
53
  });
54
- const patchContext = (context) => {
54
+ const patchContext = app.safe((context) => {
55
55
  const { insertRule, deleteRule } = context.CSSStyleSheet.prototype;
56
- const { insertRule: groupInsertRule, deleteRule: groupDeleteRule } = context.CSSGroupingRule.prototype;
56
+ const { insertRule: groupInsertRule, deleteRule: groupDeleteRule, } = context.CSSGroupingRule.prototype;
57
57
  context.CSSStyleSheet.prototype.insertRule = function (rule, index = 0) {
58
- sendInserDeleteRule(this, index, rule);
58
+ sendInsertDeleteRule(this, index, rule);
59
59
  return insertRule.call(this, rule, index);
60
60
  };
61
61
  context.CSSStyleSheet.prototype.deleteRule = function (index) {
62
- sendInserDeleteRule(this, index);
62
+ sendInsertDeleteRule(this, index);
63
63
  return deleteRule.call(this, index);
64
64
  };
65
65
  context.CSSGroupingRule.prototype.insertRule = function (rule, index = 0) {
@@ -72,7 +72,7 @@ function default_1(app) {
72
72
  sendReplaceGroupingRule(this);
73
73
  return result;
74
74
  };
75
- };
75
+ });
76
76
  patchContext(window);
77
77
  app.observer.attachContextCallback(patchContext);
78
78
  app.nodes.attachNodeCallback((node) => {
@@ -92,7 +92,7 @@ function default_1(app) {
92
92
  app.send((0, messages_gen_js_1.AdoptedSSAddOwner)(sheetID, nodeID));
93
93
  const rules = sheet.cssRules;
94
94
  for (let i = 0; i < rules.length; i++) {
95
- sendInserDeleteRule(sheet, i, rules[i].cssText);
95
+ sendInsertDeleteRule(sheet, i, rules[i].cssText);
96
96
  }
97
97
  });
98
98
  }
@@ -70,7 +70,7 @@ function default_1(app, opts) {
70
70
  app.attachEventListener(context, 'error', handler);
71
71
  }
72
72
  if (options.captureExceptions) {
73
- app.observer.attachContextCallback(patchContext);
73
+ app.observer.attachContextCallback(patchContext); // TODO: attach once-per-iframe (?)
74
74
  patchContext(window);
75
75
  }
76
76
  }
@@ -24,12 +24,12 @@ export default function (app) {
24
24
  }
25
25
  const styleSheetIDMap = new Map();
26
26
  const adoptedStyleSheetsOwnings = new Map();
27
- const sendAdoptedStyleSheetsUpdate = (root) => {
27
+ const sendAdoptedStyleSheetsUpdate = (root) => setTimeout(() => {
28
28
  let nodeID = app.nodes.getID(root);
29
29
  if (root === document) {
30
30
  nodeID = 0; // main document doesn't have nodeID. ID count starts from the documentElement
31
31
  }
32
- if (!nodeID) {
32
+ if (nodeID === undefined) {
33
33
  return;
34
34
  }
35
35
  let pastOwning = adoptedStyleSheetsOwnings.get(nodeID);
@@ -44,28 +44,31 @@ export default function (app) {
44
44
  if (!sheetID) {
45
45
  sheetID = nextID();
46
46
  }
47
- nowOwning.push(sheetID);
48
47
  if (!pastOwning.includes(sheetID)) {
49
48
  app.send(AdoptedSSAddOwner(sheetID, nodeID));
50
49
  }
51
50
  if (init) {
52
51
  const rules = s.cssRules;
53
52
  for (let i = 0; i < rules.length; i++) {
53
+ nodeID === 1110 && console.log(rules[i].cssText, root, s, root.adoptedStyleSheets[0], s.cssRules[0]);
54
54
  app.send(AdoptedSSInsertRuleURLBased(sheetID, rules[i].cssText, i, app.getBaseHref()));
55
55
  }
56
56
  }
57
+ nowOwning.push(sheetID);
57
58
  }
59
+ // nodeID === 0 && console.log(pastOwning, nowOwning, nowOwning.length)
58
60
  for (const sheetID of pastOwning) {
59
61
  if (!nowOwning.includes(sheetID)) {
60
62
  app.send(AdoptedSSRemoveOwner(sheetID, nodeID));
61
63
  }
62
64
  }
63
65
  adoptedStyleSheetsOwnings.set(nodeID, nowOwning);
64
- };
65
- function patchAdoptedStyleSheets(prototype) {
66
+ }, 0);
67
+ function patchAdoptedStyleSheets(prototype, ctx) {
66
68
  const nativeAdoptedStyleSheetsDescriptor = Object.getOwnPropertyDescriptor(prototype, 'adoptedStyleSheets');
67
69
  if (nativeAdoptedStyleSheetsDescriptor) {
68
70
  Object.defineProperty(prototype, 'adoptedStyleSheets', Object.assign(Object.assign({}, nativeAdoptedStyleSheetsDescriptor), { set: function (value) {
71
+ ctx !== window && ctx.Document.prototype === prototype && console.log("custom set!", value, ctx);
69
72
  // @ts-ignore
70
73
  const retVal = nativeAdoptedStyleSheetsDescriptor.set.call(this, value);
71
74
  sendAdoptedStyleSheetsUpdate(this);
@@ -74,6 +77,8 @@ export default function (app) {
74
77
  }
75
78
  }
76
79
  const patchContext = (context) => {
80
+ // @ts-ignore
81
+ console.log("new context", context, context.document.adoptedStyleSheets.length && context.document.adoptedStyleSheets[0].cssRules[0].cssText);
77
82
  // @ts-ignore
78
83
  if (context.__openreplay_adpss_patched__) {
79
84
  return;
@@ -82,12 +87,13 @@ export default function (app) {
82
87
  // @ts-ignore
83
88
  context.__openreplay_adpss_patched__ = true;
84
89
  }
85
- patchAdoptedStyleSheets(context.Document.prototype);
86
- patchAdoptedStyleSheets(context.ShadowRoot.prototype);
90
+ patchAdoptedStyleSheets(context.Document.prototype, context);
91
+ patchAdoptedStyleSheets(context.ShadowRoot.prototype, context);
87
92
  //@ts-ignore TODO: configure ts (use necessary lib)
88
- const { insertRule, deleteRule, replace, replaceSync } = context.CSSStyleSheet.prototype;
93
+ const { replace, replaceSync } = context.CSSStyleSheet.prototype;
89
94
  //@ts-ignore
90
95
  context.CSSStyleSheet.prototype.replace = function (text) {
96
+ styleSheetIDMap.get(this) === 102 && console.log("replace with", text);
91
97
  return replace.call(this, text).then((sheet) => {
92
98
  const sheetID = styleSheetIDMap.get(this);
93
99
  if (sheetID) {
@@ -99,6 +105,7 @@ export default function (app) {
99
105
  //@ts-ignore
100
106
  context.CSSStyleSheet.prototype.replaceSync = function (text) {
101
107
  const sheetID = styleSheetIDMap.get(this);
108
+ sheetID === 102 && console.log("replacesnc with", text);
102
109
  if (sheetID) {
103
110
  app.send(AdoptedSSReplaceURLBased(sheetID, text, app.getBaseHref()));
104
111
  }
@@ -106,7 +113,7 @@ export default function (app) {
106
113
  };
107
114
  };
108
115
  patchContext(window);
109
- app.observer.attachContextCallback(patchContext);
116
+ app.observer.attachContextCallback(app.safe(patchContext));
110
117
  app.attachStopCallback(() => {
111
118
  styleSheetIDMap.clear();
112
119
  adoptedStyleSheetsOwnings.clear();
@@ -10,7 +10,7 @@ export default function (app) {
10
10
  app.send(TechnicalInfo('no_stylesheet_prototype_in_window', ''));
11
11
  return;
12
12
  }
13
- const sendInserDeleteRule = app.safe((sheet, index, rule) => {
13
+ const sendInsertDeleteRule = app.safe((sheet, index, rule) => {
14
14
  const sheetID = styleSheetIDMap.get(sheet);
15
15
  if (!sheetID) {
16
16
  // OK-case. Sheet haven't been registered yet. Rules will be sent on registration.
@@ -50,15 +50,15 @@ export default function (app) {
50
50
  app.debug.warn('Rule index not found in', sheet, topmostRule);
51
51
  }
52
52
  });
53
- const patchContext = (context) => {
53
+ const patchContext = app.safe((context) => {
54
54
  const { insertRule, deleteRule } = context.CSSStyleSheet.prototype;
55
- const { insertRule: groupInsertRule, deleteRule: groupDeleteRule } = context.CSSGroupingRule.prototype;
55
+ const { insertRule: groupInsertRule, deleteRule: groupDeleteRule, } = context.CSSGroupingRule.prototype;
56
56
  context.CSSStyleSheet.prototype.insertRule = function (rule, index = 0) {
57
- sendInserDeleteRule(this, index, rule);
57
+ sendInsertDeleteRule(this, index, rule);
58
58
  return insertRule.call(this, rule, index);
59
59
  };
60
60
  context.CSSStyleSheet.prototype.deleteRule = function (index) {
61
- sendInserDeleteRule(this, index);
61
+ sendInsertDeleteRule(this, index);
62
62
  return deleteRule.call(this, index);
63
63
  };
64
64
  context.CSSGroupingRule.prototype.insertRule = function (rule, index = 0) {
@@ -71,7 +71,7 @@ export default function (app) {
71
71
  sendReplaceGroupingRule(this);
72
72
  return result;
73
73
  };
74
- };
74
+ });
75
75
  patchContext(window);
76
76
  app.observer.attachContextCallback(patchContext);
77
77
  app.nodes.attachNodeCallback((node) => {
@@ -91,7 +91,7 @@ export default function (app) {
91
91
  app.send(AdoptedSSAddOwner(sheetID, nodeID));
92
92
  const rules = sheet.cssRules;
93
93
  for (let i = 0; i < rules.length; i++) {
94
- sendInserDeleteRule(sheet, i, rules[i].cssText);
94
+ sendInsertDeleteRule(sheet, i, rules[i].cssText);
95
95
  }
96
96
  });
97
97
  }
@@ -65,7 +65,7 @@ export default function (app, opts) {
65
65
  app.attachEventListener(context, 'error', handler);
66
66
  }
67
67
  if (options.captureExceptions) {
68
- app.observer.attachContextCallback(patchContext);
68
+ app.observer.attachContextCallback(patchContext); // TODO: attach once-per-iframe (?)
69
69
  patchContext(window);
70
70
  }
71
71
  }
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": "4.1.4-beta",
4
+ "version": "4.1.4-beta.0",
5
5
  "keywords": [
6
6
  "logging",
7
7
  "replay"