@openreplay/tracker 5.0.1 → 5.0.2-beta

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.
Files changed (135) hide show
  1. package/package.json +1 -1
  2. package/cjs/app/guards.d.ts +0 -21
  3. package/cjs/app/guards.js +0 -37
  4. package/cjs/app/index.d.ts +0 -118
  5. package/cjs/app/index.js +0 -438
  6. package/cjs/app/logger.d.ts +0 -26
  7. package/cjs/app/logger.js +0 -45
  8. package/cjs/app/messages.gen.d.ts +0 -63
  9. package/cjs/app/messages.gen.js +0 -551
  10. package/cjs/app/nodes.d.ts +0 -18
  11. package/cjs/app/nodes.js +0 -82
  12. package/cjs/app/observer/iframe_observer.d.ts +0 -4
  13. package/cjs/app/observer/iframe_observer.js +0 -23
  14. package/cjs/app/observer/iframe_offsets.d.ts +0 -8
  15. package/cjs/app/observer/iframe_offsets.js +0 -59
  16. package/cjs/app/observer/observer.d.ts +0 -23
  17. package/cjs/app/observer/observer.js +0 -340
  18. package/cjs/app/observer/shadow_root_observer.d.ts +0 -4
  19. package/cjs/app/observer/shadow_root_observer.js +0 -21
  20. package/cjs/app/observer/top_observer.d.ts +0 -24
  21. package/cjs/app/observer/top_observer.js +0 -113
  22. package/cjs/app/sanitizer.d.ts +0 -24
  23. package/cjs/app/sanitizer.js +0 -76
  24. package/cjs/app/session.d.ts +0 -38
  25. package/cjs/app/session.js +0 -114
  26. package/cjs/app/ticker.d.ts +0 -12
  27. package/cjs/app/ticker.js +0 -42
  28. package/cjs/common/interaction.d.ts +0 -24
  29. package/cjs/common/interaction.js +0 -2
  30. package/cjs/common/messages.gen.d.ts +0 -427
  31. package/cjs/common/messages.gen.js +0 -4
  32. package/cjs/index.d.ts +0 -47
  33. package/cjs/index.js +0 -254
  34. package/cjs/modules/connection.d.ts +0 -2
  35. package/cjs/modules/connection.js +0 -15
  36. package/cjs/modules/console.d.ts +0 -6
  37. package/cjs/modules/console.js +0 -119
  38. package/cjs/modules/constructedStyleSheets.d.ts +0 -4
  39. package/cjs/modules/constructedStyleSheets.js +0 -131
  40. package/cjs/modules/cssrules.d.ts +0 -2
  41. package/cjs/modules/cssrules.js +0 -99
  42. package/cjs/modules/exception.d.ts +0 -16
  43. package/cjs/modules/exception.js +0 -77
  44. package/cjs/modules/focus.d.ts +0 -2
  45. package/cjs/modules/focus.js +0 -45
  46. package/cjs/modules/fonts.d.ts +0 -2
  47. package/cjs/modules/fonts.js +0 -57
  48. package/cjs/modules/img.d.ts +0 -2
  49. package/cjs/modules/img.js +0 -110
  50. package/cjs/modules/input.d.ts +0 -16
  51. package/cjs/modules/input.js +0 -163
  52. package/cjs/modules/mouse.d.ts +0 -2
  53. package/cjs/modules/mouse.js +0 -148
  54. package/cjs/modules/network.d.ts +0 -28
  55. package/cjs/modules/network.js +0 -203
  56. package/cjs/modules/performance.d.ts +0 -7
  57. package/cjs/modules/performance.js +0 -53
  58. package/cjs/modules/scroll.d.ts +0 -2
  59. package/cjs/modules/scroll.js +0 -79
  60. package/cjs/modules/timing.d.ts +0 -7
  61. package/cjs/modules/timing.js +0 -160
  62. package/cjs/modules/viewport.d.ts +0 -2
  63. package/cjs/modules/viewport.js +0 -43
  64. package/cjs/package.json +0 -1
  65. package/cjs/utils.d.ts +0 -13
  66. package/cjs/utils.js +0 -71
  67. package/cjs/vendors/finder/finder.d.ts +0 -12
  68. package/cjs/vendors/finder/finder.js +0 -352
  69. package/lib/app/guards.d.ts +0 -21
  70. package/lib/app/guards.js +0 -26
  71. package/lib/app/index.d.ts +0 -118
  72. package/lib/app/index.js +0 -434
  73. package/lib/app/logger.d.ts +0 -26
  74. package/lib/app/logger.js +0 -41
  75. package/lib/app/messages.gen.d.ts +0 -63
  76. package/lib/app/messages.gen.js +0 -486
  77. package/lib/app/nodes.d.ts +0 -18
  78. package/lib/app/nodes.js +0 -79
  79. package/lib/app/observer/iframe_observer.d.ts +0 -4
  80. package/lib/app/observer/iframe_observer.js +0 -20
  81. package/lib/app/observer/iframe_offsets.d.ts +0 -8
  82. package/lib/app/observer/iframe_offsets.js +0 -56
  83. package/lib/app/observer/observer.d.ts +0 -23
  84. package/lib/app/observer/observer.js +0 -337
  85. package/lib/app/observer/shadow_root_observer.d.ts +0 -4
  86. package/lib/app/observer/shadow_root_observer.js +0 -18
  87. package/lib/app/observer/top_observer.d.ts +0 -24
  88. package/lib/app/observer/top_observer.js +0 -110
  89. package/lib/app/sanitizer.d.ts +0 -24
  90. package/lib/app/sanitizer.js +0 -72
  91. package/lib/app/session.d.ts +0 -38
  92. package/lib/app/session.js +0 -111
  93. package/lib/app/ticker.d.ts +0 -12
  94. package/lib/app/ticker.js +0 -39
  95. package/lib/common/interaction.d.ts +0 -24
  96. package/lib/common/interaction.js +0 -1
  97. package/lib/common/messages.gen.d.ts +0 -427
  98. package/lib/common/messages.gen.js +0 -3
  99. package/lib/common/tsconfig.tsbuildinfo +0 -1
  100. package/lib/index.d.ts +0 -47
  101. package/lib/index.js +0 -248
  102. package/lib/modules/connection.d.ts +0 -2
  103. package/lib/modules/connection.js +0 -12
  104. package/lib/modules/console.d.ts +0 -6
  105. package/lib/modules/console.js +0 -116
  106. package/lib/modules/constructedStyleSheets.d.ts +0 -4
  107. package/lib/modules/constructedStyleSheets.js +0 -126
  108. package/lib/modules/cssrules.d.ts +0 -2
  109. package/lib/modules/cssrules.js +0 -97
  110. package/lib/modules/exception.d.ts +0 -16
  111. package/lib/modules/exception.js +0 -71
  112. package/lib/modules/focus.d.ts +0 -2
  113. package/lib/modules/focus.js +0 -42
  114. package/lib/modules/fonts.d.ts +0 -2
  115. package/lib/modules/fonts.js +0 -54
  116. package/lib/modules/img.d.ts +0 -2
  117. package/lib/modules/img.js +0 -107
  118. package/lib/modules/input.d.ts +0 -16
  119. package/lib/modules/input.js +0 -158
  120. package/lib/modules/mouse.d.ts +0 -2
  121. package/lib/modules/mouse.js +0 -145
  122. package/lib/modules/network.d.ts +0 -28
  123. package/lib/modules/network.js +0 -200
  124. package/lib/modules/performance.d.ts +0 -7
  125. package/lib/modules/performance.js +0 -49
  126. package/lib/modules/scroll.d.ts +0 -2
  127. package/lib/modules/scroll.js +0 -76
  128. package/lib/modules/timing.d.ts +0 -7
  129. package/lib/modules/timing.js +0 -157
  130. package/lib/modules/viewport.d.ts +0 -2
  131. package/lib/modules/viewport.js +0 -40
  132. package/lib/utils.d.ts +0 -13
  133. package/lib/utils.js +0 -61
  134. package/lib/vendors/finder/finder.d.ts +0 -12
  135. package/lib/vendors/finder/finder.js +0 -348
package/cjs/index.js DELETED
@@ -1,254 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SanitizeLevel = exports.Messages = exports.App = void 0;
4
- const index_js_1 = require("./app/index.js");
5
- var index_js_2 = require("./app/index.js");
6
- Object.defineProperty(exports, "App", { enumerable: true, get: function () { return index_js_2.default; } });
7
- const messages_gen_js_1 = require("./app/messages.gen.js");
8
- const _Messages = require("./app/messages.gen.js");
9
- exports.Messages = _Messages;
10
- var sanitizer_js_1 = require("./app/sanitizer.js");
11
- Object.defineProperty(exports, "SanitizeLevel", { enumerable: true, get: function () { return sanitizer_js_1.SanitizeLevel; } });
12
- const connection_js_1 = require("./modules/connection.js");
13
- const console_js_1 = require("./modules/console.js");
14
- const exception_js_1 = require("./modules/exception.js");
15
- const img_js_1 = require("./modules/img.js");
16
- const input_js_1 = require("./modules/input.js");
17
- const mouse_js_1 = require("./modules/mouse.js");
18
- const timing_js_1 = require("./modules/timing.js");
19
- const performance_js_1 = require("./modules/performance.js");
20
- const scroll_js_1 = require("./modules/scroll.js");
21
- const viewport_js_1 = require("./modules/viewport.js");
22
- const cssrules_js_1 = require("./modules/cssrules.js");
23
- const focus_js_1 = require("./modules/focus.js");
24
- const fonts_js_1 = require("./modules/fonts.js");
25
- const network_js_1 = require("./modules/network.js");
26
- const constructedStyleSheets_js_1 = require("./modules/constructedStyleSheets.js");
27
- const utils_js_1 = require("./utils.js");
28
- const DOCS_SETUP = '/installation/javascript-sdk';
29
- function processOptions(obj) {
30
- if (obj == null) {
31
- console.error(`OpenReplay: invalid options argument type. Please, check documentation on ${utils_js_1.DOCS_HOST}${DOCS_SETUP}`);
32
- return false;
33
- }
34
- if (typeof obj.projectKey !== 'string') {
35
- if (typeof obj.projectKey !== 'number') {
36
- if (typeof obj.projectID !== 'number') {
37
- // Back compatability
38
- console.error(`OpenReplay: projectKey is missing or wrong type (string is expected). Please, check ${utils_js_1.DOCS_HOST}${DOCS_SETUP} for more information.`);
39
- return false;
40
- }
41
- else {
42
- obj.projectKey = obj.projectID.toString();
43
- (0, utils_js_1.deprecationWarn)('`projectID` option', '`projectKey` option', DOCS_SETUP);
44
- }
45
- }
46
- else {
47
- console.warn('OpenReplay: projectKey is expected to have a string type.');
48
- obj.projectKey = obj.projectKey.toString();
49
- }
50
- }
51
- if (obj.sessionToken != null) {
52
- (0, utils_js_1.deprecationWarn)('`sessionToken` option', '`sessionHash` start() option', '/');
53
- }
54
- return true;
55
- }
56
- class API {
57
- constructor(options) {
58
- this.options = options;
59
- this.app = null;
60
- this.handleError = (e, metadata = {}) => {
61
- if (this.app === null) {
62
- return;
63
- }
64
- if (e instanceof Error) {
65
- const msg = (0, exception_js_1.getExceptionMessage)(e, [], metadata);
66
- this.app.send(msg);
67
- }
68
- else if (e instanceof ErrorEvent ||
69
- ('PromiseRejectionEvent' in window && e instanceof PromiseRejectionEvent)) {
70
- const msg = (0, exception_js_1.getExceptionMessageFromEvent)(e, undefined, metadata);
71
- if (msg != null) {
72
- this.app.send(msg);
73
- }
74
- }
75
- };
76
- if (!utils_js_1.IN_BROWSER || !processOptions(options)) {
77
- return;
78
- }
79
- if (window.__OPENREPLAY__) {
80
- console.error('OpenReplay: one tracker instance has been initialised already');
81
- return;
82
- }
83
- if (!options.__DISABLE_SECURE_MODE && location.protocol !== 'https:') {
84
- console.error('OpenReplay: Your website must be publicly accessible and running on SSL in order for OpenReplay to properly capture and replay the user session. You can disable this check by setting `__DISABLE_SECURE_MODE` option to `true` if you are testing in localhost. Keep in mind, that asset files on a local machine are not available to the outside world. This might affect tracking if you use css files.');
85
- return;
86
- }
87
- const doNotTrack = options.respectDoNotTrack &&
88
- (navigator.doNotTrack == '1' ||
89
- // @ts-ignore
90
- window.doNotTrack == '1');
91
- const app = (this.app =
92
- doNotTrack ||
93
- !('Map' in window) ||
94
- !('Set' in window) ||
95
- !('MutationObserver' in window) ||
96
- !('performance' in window) ||
97
- !('timing' in performance) ||
98
- !('startsWith' in String.prototype) ||
99
- !('Blob' in window) ||
100
- !('Worker' in window)
101
- ? null
102
- : new index_js_1.default(options.projectKey, options.sessionToken, options));
103
- if (app !== null) {
104
- (0, viewport_js_1.default)(app);
105
- (0, cssrules_js_1.default)(app);
106
- (0, constructedStyleSheets_js_1.default)(app);
107
- (0, connection_js_1.default)(app);
108
- (0, console_js_1.default)(app, options);
109
- (0, exception_js_1.default)(app, options);
110
- (0, img_js_1.default)(app);
111
- (0, input_js_1.default)(app, options);
112
- (0, mouse_js_1.default)(app);
113
- (0, timing_js_1.default)(app, options);
114
- (0, performance_js_1.default)(app, options);
115
- (0, scroll_js_1.default)(app);
116
- (0, focus_js_1.default)(app);
117
- (0, fonts_js_1.default)(app);
118
- (0, network_js_1.default)(app, options.network);
119
- window.__OPENREPLAY__ = this;
120
- if (options.autoResetOnWindowOpen) {
121
- const wOpen = window.open;
122
- app.attachStartCallback(() => {
123
- // @ts-ignore ?
124
- window.open = function (...args) {
125
- app.resetNextPageSession(true);
126
- wOpen.call(window, ...args);
127
- app.resetNextPageSession(false);
128
- };
129
- });
130
- app.attachStopCallback(() => {
131
- window.open = wOpen;
132
- });
133
- }
134
- }
135
- else {
136
- console.log("OpenReplay: browser doesn't support API required for tracking or doNotTrack is set to 1.");
137
- const req = new XMLHttpRequest();
138
- const orig = options.ingestPoint || index_js_1.DEFAULT_INGEST_POINT;
139
- req.open('POST', orig + '/v1/web/not-started');
140
- // no-cors issue only with text/plain or not-set Content-Type
141
- // req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
142
- req.send(JSON.stringify({
143
- trackerVersion: '5.0.1',
144
- projectKey: options.projectKey,
145
- doNotTrack,
146
- // TODO: add precise reason (an exact API missing)
147
- }));
148
- }
149
- }
150
- use(fn) {
151
- return fn(this.app, this.options);
152
- }
153
- isActive() {
154
- if (this.app === null) {
155
- return false;
156
- }
157
- return this.app.active();
158
- }
159
- start(startOpts) {
160
- if (!utils_js_1.IN_BROWSER) {
161
- console.error(`OpenReplay: you are trying to start Tracker on a node.js environment. If you want to use OpenReplay with SSR, please, use componentDidMount or useEffect API for placing the \`tracker.start()\` line. Check documentation on ${utils_js_1.DOCS_HOST}${DOCS_SETUP}`);
162
- return Promise.reject('Trying to start not in browser.');
163
- }
164
- if (this.app === null) {
165
- return Promise.reject("Browser doesn't support required api, or doNotTrack is active.");
166
- }
167
- // TODO: check argument type
168
- return this.app.start(startOpts);
169
- }
170
- stop() {
171
- if (this.app === null) {
172
- return;
173
- }
174
- this.app.stop();
175
- return this.app.session.getSessionHash();
176
- }
177
- getSessionToken() {
178
- if (this.app === null) {
179
- return null;
180
- }
181
- return this.app.getSessionToken();
182
- }
183
- getSessionID() {
184
- if (this.app === null) {
185
- return null;
186
- }
187
- return this.app.getSessionID();
188
- }
189
- sessionID() {
190
- (0, utils_js_1.deprecationWarn)("'sessionID' method", "'getSessionID' method", '/');
191
- return this.getSessionID();
192
- }
193
- getSessionURL(options) {
194
- if (this.app === null) {
195
- return undefined;
196
- }
197
- return this.app.getSessionURL(options);
198
- }
199
- setUserID(id) {
200
- if (typeof id === 'string' && this.app !== null) {
201
- this.app.session.setUserID(id);
202
- }
203
- }
204
- userID(id) {
205
- (0, utils_js_1.deprecationWarn)("'userID' method", "'setUserID' method", '/');
206
- this.setUserID(id);
207
- }
208
- setUserAnonymousID(id) {
209
- if (typeof id === 'string' && this.app !== null) {
210
- this.app.send((0, messages_gen_js_1.UserAnonymousID)(id));
211
- }
212
- }
213
- userAnonymousID(id) {
214
- (0, utils_js_1.deprecationWarn)("'userAnonymousID' method", "'setUserAnonymousID' method", '/');
215
- this.setUserAnonymousID(id);
216
- }
217
- setMetadata(key, value) {
218
- if (typeof key === 'string' && typeof value === 'string' && this.app !== null) {
219
- this.app.session.setMetadata(key, value);
220
- }
221
- }
222
- metadata(key, value) {
223
- (0, utils_js_1.deprecationWarn)("'metadata' method", "'setMetadata' method", '/');
224
- this.setMetadata(key, value);
225
- }
226
- event(key, payload = null, issue = false) {
227
- if (typeof key === 'string' && this.app !== null) {
228
- if (issue) {
229
- return this.issue(key, payload);
230
- }
231
- else {
232
- try {
233
- payload = JSON.stringify(payload);
234
- }
235
- catch (e) {
236
- return;
237
- }
238
- this.app.send((0, messages_gen_js_1.CustomEvent)(key, payload));
239
- }
240
- }
241
- }
242
- issue(key, payload = null) {
243
- if (typeof key === 'string' && this.app !== null) {
244
- try {
245
- payload = JSON.stringify(payload);
246
- }
247
- catch (e) {
248
- return;
249
- }
250
- this.app.send((0, messages_gen_js_1.CustomIssue)(key, payload));
251
- }
252
- }
253
- }
254
- exports.default = API;
@@ -1,2 +0,0 @@
1
- import App from '../app/index.js';
2
- export default function (app: App): void;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const messages_gen_js_1 = require("../app/messages.gen.js");
4
- function default_1(app) {
5
- const connection = navigator.connection ||
6
- navigator.mozConnection ||
7
- navigator.webkitConnection;
8
- if (connection === undefined) {
9
- return;
10
- }
11
- const sendConnectionInformation = () => app.send((0, messages_gen_js_1.ConnectionInformation)(Math.round(connection.downlink * 1000), connection.type || 'unknown'));
12
- sendConnectionInformation();
13
- connection.addEventListener('change', sendConnectionInformation);
14
- }
15
- exports.default = default_1;
@@ -1,6 +0,0 @@
1
- import type App from '../app/index.js';
2
- export interface Options {
3
- consoleMethods: Array<string> | null;
4
- consoleThrottling: number;
5
- }
6
- export default function (app: App, opts: Partial<Options>): void;
@@ -1,119 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_js_1 = require("../utils.js");
4
- const messages_gen_js_1 = require("../app/messages.gen.js");
5
- const printError = utils_js_1.IN_BROWSER && 'InstallTrigger' in window // detect Firefox
6
- ? (e) => e.message + '\n' + e.stack
7
- : (e) => e.stack || e.message;
8
- function printString(arg) {
9
- if (arg === undefined) {
10
- return 'undefined';
11
- }
12
- if (arg === null) {
13
- return 'null';
14
- }
15
- if (arg instanceof Error) {
16
- return printError(arg);
17
- }
18
- if (Array.isArray(arg)) {
19
- return `Array(${arg.length})`;
20
- }
21
- return String(arg);
22
- }
23
- function printFloat(arg) {
24
- if (typeof arg !== 'number')
25
- return 'NaN';
26
- return arg.toString();
27
- }
28
- function printInt(arg) {
29
- if (typeof arg !== 'number')
30
- return 'NaN';
31
- return Math.floor(arg).toString();
32
- }
33
- function printObject(arg) {
34
- if (arg === undefined) {
35
- return 'undefined';
36
- }
37
- if (arg === null) {
38
- return 'null';
39
- }
40
- if (arg instanceof Error) {
41
- return printError(arg);
42
- }
43
- if (Array.isArray(arg)) {
44
- const length = arg.length;
45
- const values = arg.slice(0, 10).map(printString).join(', ');
46
- return `Array(${length})[${values}]`;
47
- }
48
- if (typeof arg === 'object') {
49
- const res = [];
50
- let i = 0;
51
- for (const k in arg) {
52
- if (++i === 10) {
53
- break;
54
- }
55
- const v = arg[k];
56
- res.push(k + ': ' + printString(v));
57
- }
58
- return '{' + res.join(', ') + '}';
59
- }
60
- return arg.toString();
61
- }
62
- function printf(args) {
63
- if (typeof args[0] === 'string') {
64
- args.unshift(args.shift().replace(/%(o|s|f|d|i)/g, (s, t) => {
65
- const arg = args.shift();
66
- if (arg === undefined)
67
- return s;
68
- switch (t) {
69
- case 'o':
70
- return printObject(arg);
71
- case 's':
72
- return printString(arg);
73
- case 'f':
74
- return printFloat(arg);
75
- case 'd':
76
- case 'i':
77
- return printInt(arg);
78
- default:
79
- return s;
80
- }
81
- }));
82
- }
83
- return args.map(printObject).join(' ');
84
- }
85
- const consoleMethods = ['log', 'info', 'warn', 'error', 'debug', 'assert'];
86
- function default_1(app, opts) {
87
- const options = Object.assign({
88
- consoleMethods,
89
- consoleThrottling: 30,
90
- }, opts);
91
- if (!Array.isArray(options.consoleMethods) || options.consoleMethods.length === 0) {
92
- return;
93
- }
94
- const sendConsoleLog = app.safe((level, args) => app.send((0, messages_gen_js_1.ConsoleLog)(level, printf(args))));
95
- let n;
96
- const reset = () => {
97
- n = 0;
98
- };
99
- app.attachStartCallback(reset);
100
- app.ticker.attach(reset, 33, false);
101
- const patchConsole = (console) => options.consoleMethods.forEach((method) => {
102
- if (consoleMethods.indexOf(method) === -1) {
103
- app.debug.error(`OpenReplay: unsupported console method "${method}"`);
104
- return;
105
- }
106
- const fn = console[method];
107
- console[method] = function (...args) {
108
- fn.apply(this, args);
109
- if (n++ > options.consoleThrottling) {
110
- return;
111
- }
112
- sendConsoleLog(method, args);
113
- };
114
- });
115
- const patchContext = app.safe((context) => patchConsole(context.console));
116
- patchContext(window);
117
- app.observer.attachContextCallback(patchContext);
118
- }
119
- exports.default = default_1;
@@ -1,4 +0,0 @@
1
- import type App from '../app/index.js';
2
- export declare function nextID(): number;
3
- export declare const styleSheetIDMap: Map<CSSStyleSheet, number>;
4
- export default function (app: App | null): void;
@@ -1,131 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.styleSheetIDMap = exports.nextID = void 0;
4
- const messages_gen_js_1 = require("../app/messages.gen.js");
5
- const guards_js_1 = require("../app/guards.js");
6
- function hasAdoptedSS(node) {
7
- return ((0, guards_js_1.isRootNode)(node) &&
8
- // @ts-ignore
9
- !!node.adoptedStyleSheets);
10
- }
11
- // TODO: incapsulate to be init-ed on-start and join with cssrules.ts under one folder
12
- let _id = 0xf;
13
- function nextID() {
14
- return _id++;
15
- }
16
- exports.nextID = nextID;
17
- exports.styleSheetIDMap = new Map();
18
- function default_1(app) {
19
- if (app === null) {
20
- return;
21
- }
22
- if (!hasAdoptedSS(document)) {
23
- return;
24
- }
25
- const styleSheetIDMap = new Map();
26
- const adoptedStyleSheetsOwnings = new Map();
27
- const sendAdoptedStyleSheetsUpdate = (root) => setTimeout(() => {
28
- let nodeID = app.nodes.getID(root);
29
- if (root === document) {
30
- nodeID = 0; // main document doesn't have nodeID. ID count starts from the documentElement
31
- }
32
- if (nodeID === undefined) {
33
- return;
34
- }
35
- let pastOwning = adoptedStyleSheetsOwnings.get(nodeID);
36
- if (!pastOwning) {
37
- pastOwning = [];
38
- }
39
- const nowOwning = [];
40
- const styleSheets = root.adoptedStyleSheets;
41
- for (const s of styleSheets) {
42
- let sheetID = styleSheetIDMap.get(s);
43
- const init = !sheetID;
44
- if (!sheetID) {
45
- sheetID = nextID();
46
- styleSheetIDMap.set(s, sheetID);
47
- }
48
- if (!pastOwning.includes(sheetID)) {
49
- app.send((0, messages_gen_js_1.AdoptedSSAddOwner)(sheetID, nodeID));
50
- }
51
- if (init) {
52
- const rules = s.cssRules;
53
- for (let i = 0; i < rules.length; i++) {
54
- app.send((0, messages_gen_js_1.AdoptedSSInsertRuleURLBased)(sheetID, rules[i].cssText, i, app.getBaseHref()));
55
- }
56
- }
57
- nowOwning.push(sheetID);
58
- }
59
- for (const sheetID of pastOwning) {
60
- if (!nowOwning.includes(sheetID)) {
61
- app.send((0, messages_gen_js_1.AdoptedSSRemoveOwner)(sheetID, nodeID));
62
- }
63
- }
64
- adoptedStyleSheetsOwnings.set(nodeID, nowOwning);
65
- }, 20); // Misterious bug:
66
- /* On the page https://explore.fast.design/components/fast-accordion
67
- the only rule inside the only adoptedStyleSheet of the iframe-s document
68
- gets changed during first milliseconds after the load.
69
- Howerer, none of the documented methods (replace, insertRule) is triggered.
70
- The rule is not substituted (remains the same object), however the text gets changed.
71
- */
72
- function patchAdoptedStyleSheets(prototype) {
73
- const nativeAdoptedStyleSheetsDescriptor = Object.getOwnPropertyDescriptor(prototype, 'adoptedStyleSheets');
74
- if (nativeAdoptedStyleSheetsDescriptor) {
75
- Object.defineProperty(prototype, 'adoptedStyleSheets', Object.assign(Object.assign({}, nativeAdoptedStyleSheetsDescriptor), { set: function (value) {
76
- // @ts-ignore
77
- const retVal = nativeAdoptedStyleSheetsDescriptor.set.call(this, value);
78
- sendAdoptedStyleSheetsUpdate(this);
79
- return retVal;
80
- } }));
81
- }
82
- }
83
- const patchContext = (context) => {
84
- // @ts-ignore
85
- if (context.__openreplay_adpss_patched__) {
86
- return;
87
- }
88
- else {
89
- // @ts-ignore
90
- context.__openreplay_adpss_patched__ = true;
91
- }
92
- patchAdoptedStyleSheets(context.Document.prototype);
93
- patchAdoptedStyleSheets(context.ShadowRoot.prototype);
94
- //@ts-ignore TODO: upgrade ts to 4.8+
95
- const { replace, replaceSync } = context.CSSStyleSheet.prototype;
96
- //@ts-ignore
97
- context.CSSStyleSheet.prototype.replace = function (text) {
98
- return replace.call(this, text).then((sheet) => {
99
- const sheetID = styleSheetIDMap.get(this);
100
- if (sheetID) {
101
- app.send((0, messages_gen_js_1.AdoptedSSReplaceURLBased)(sheetID, text, app.getBaseHref()));
102
- }
103
- return sheet;
104
- });
105
- };
106
- //@ts-ignore
107
- context.CSSStyleSheet.prototype.replaceSync = function (text) {
108
- const sheetID = styleSheetIDMap.get(this);
109
- if (sheetID) {
110
- app.send((0, messages_gen_js_1.AdoptedSSReplaceURLBased)(sheetID, text, app.getBaseHref()));
111
- }
112
- return replaceSync.call(this, text);
113
- };
114
- };
115
- patchContext(window);
116
- app.observer.attachContextCallback(app.safe(patchContext));
117
- app.attachStopCallback(() => {
118
- styleSheetIDMap.clear();
119
- adoptedStyleSheetsOwnings.clear();
120
- });
121
- // So far main Document is not triggered with nodeCallbacks
122
- app.attachStartCallback(() => {
123
- sendAdoptedStyleSheetsUpdate(document);
124
- });
125
- app.nodes.attachNodeCallback((node) => {
126
- if (hasAdoptedSS(node)) {
127
- sendAdoptedStyleSheetsUpdate(node);
128
- }
129
- });
130
- }
131
- exports.default = default_1;
@@ -1,2 +0,0 @@
1
- import type App from '../app/index.js';
2
- export default function (app: App | null): void;
@@ -1,99 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const messages_gen_js_1 = require("../app/messages.gen.js");
4
- const guards_js_1 = require("../app/guards.js");
5
- const constructedStyleSheets_js_1 = require("./constructedStyleSheets.js");
6
- function default_1(app) {
7
- if (app === null) {
8
- return;
9
- }
10
- if (!window.CSSStyleSheet) {
11
- app.send((0, messages_gen_js_1.TechnicalInfo)('no_stylesheet_prototype_in_window', ''));
12
- return;
13
- }
14
- const sendInsertDeleteRule = app.safe((sheet, index, rule) => {
15
- const sheetID = constructedStyleSheets_js_1.styleSheetIDMap.get(sheet);
16
- if (!sheetID) {
17
- // OK-case. Sheet haven't been registered yet. Rules will be sent on registration.
18
- return;
19
- }
20
- if (typeof rule === 'string') {
21
- app.send((0, messages_gen_js_1.AdoptedSSInsertRuleURLBased)(sheetID, rule, index, app.getBaseHref()));
22
- }
23
- else {
24
- app.send((0, messages_gen_js_1.AdoptedSSDeleteRule)(sheetID, index));
25
- }
26
- });
27
- // TODO: proper rule insertion/removal (how?)
28
- const sendReplaceGroupingRule = app.safe((rule) => {
29
- let topmostRule = rule;
30
- while (topmostRule.parentRule) {
31
- topmostRule = topmostRule.parentRule;
32
- }
33
- const sheet = topmostRule.parentStyleSheet;
34
- if (!sheet) {
35
- app.debug.warn('No parent StyleSheet found for', topmostRule, rule);
36
- return;
37
- }
38
- const sheetID = constructedStyleSheets_js_1.styleSheetIDMap.get(sheet);
39
- if (!sheetID) {
40
- app.debug.warn('No sheedID found for', sheet, constructedStyleSheets_js_1.styleSheetIDMap);
41
- return;
42
- }
43
- const cssText = topmostRule.cssText;
44
- const ruleList = sheet.cssRules;
45
- const idx = Array.from(ruleList).indexOf(topmostRule);
46
- if (idx >= 0) {
47
- app.send((0, messages_gen_js_1.AdoptedSSInsertRuleURLBased)(sheetID, cssText, idx, app.getBaseHref()));
48
- app.send((0, messages_gen_js_1.AdoptedSSDeleteRule)(sheetID, idx + 1)); // Remove previous clone
49
- }
50
- else {
51
- app.debug.warn('Rule index not found in', sheet, topmostRule);
52
- }
53
- });
54
- const patchContext = app.safe((context) => {
55
- const { insertRule, deleteRule } = context.CSSStyleSheet.prototype;
56
- const { insertRule: groupInsertRule, deleteRule: groupDeleteRule } = context.CSSGroupingRule.prototype;
57
- context.CSSStyleSheet.prototype.insertRule = function (rule, index = 0) {
58
- sendInsertDeleteRule(this, index, rule);
59
- return insertRule.call(this, rule, index);
60
- };
61
- context.CSSStyleSheet.prototype.deleteRule = function (index) {
62
- sendInsertDeleteRule(this, index);
63
- return deleteRule.call(this, index);
64
- };
65
- context.CSSGroupingRule.prototype.insertRule = function (rule, index = 0) {
66
- const result = groupInsertRule.call(this, rule, index);
67
- sendReplaceGroupingRule(this);
68
- return result;
69
- };
70
- context.CSSGroupingRule.prototype.deleteRule = function (index = 0) {
71
- const result = groupDeleteRule.call(this, index);
72
- sendReplaceGroupingRule(this);
73
- return result;
74
- };
75
- });
76
- patchContext(window);
77
- app.observer.attachContextCallback(patchContext);
78
- app.nodes.attachNodeCallback((node) => {
79
- if (!(0, guards_js_1.hasTag)(node, 'style') || !node.sheet) {
80
- return;
81
- }
82
- if (node.textContent !== null && node.textContent.trim().length > 0) {
83
- return; // Non-virtual styles captured by the observer as a text
84
- }
85
- const nodeID = app.nodes.getID(node);
86
- if (!nodeID) {
87
- return;
88
- }
89
- const sheet = node.sheet;
90
- const sheetID = (0, constructedStyleSheets_js_1.nextID)();
91
- constructedStyleSheets_js_1.styleSheetIDMap.set(sheet, sheetID);
92
- app.send((0, messages_gen_js_1.AdoptedSSAddOwner)(sheetID, nodeID));
93
- const rules = sheet.cssRules;
94
- for (let i = 0; i < rules.length; i++) {
95
- sendInsertDeleteRule(sheet, i, rules[i].cssText);
96
- }
97
- });
98
- }
99
- exports.default = default_1;
@@ -1,16 +0,0 @@
1
- import type App from '../app/index.js';
2
- import type Message from '../app/messages.gen.js';
3
- export interface Options {
4
- captureExceptions: boolean;
5
- }
6
- interface StackFrame {
7
- columnNumber?: number;
8
- lineNumber?: number;
9
- fileName?: string;
10
- functionName?: string;
11
- source?: string;
12
- }
13
- export declare function getExceptionMessage(error: Error, fallbackStack: Array<StackFrame>, metadata?: Record<string, any>): Message;
14
- export declare function getExceptionMessageFromEvent(e: ErrorEvent | PromiseRejectionEvent, context?: typeof globalThis, metadata?: Record<string, any>): Message | null;
15
- export default function (app: App, opts: Partial<Options>): void;
16
- export {};