@openreplay/tracker 3.6.1 → 3.6.2

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 (128) hide show
  1. package/LICENSE +1 -1
  2. package/cjs/app/guards.d.ts +1 -2
  3. package/cjs/app/guards.js +3 -6
  4. package/cjs/app/index.d.ts +23 -28
  5. package/cjs/app/index.js +86 -107
  6. package/cjs/app/logger.js +3 -6
  7. package/cjs/app/nodes.d.ts +1 -1
  8. package/cjs/app/nodes.js +0 -2
  9. package/cjs/app/observer/iframe_observer.d.ts +1 -1
  10. package/cjs/app/observer/iframe_observer.js +3 -3
  11. package/cjs/app/observer/observer.d.ts +3 -2
  12. package/cjs/app/observer/observer.js +52 -50
  13. package/cjs/app/observer/shadow_root_observer.d.ts +1 -1
  14. package/cjs/app/observer/shadow_root_observer.js +3 -3
  15. package/cjs/app/observer/top_observer.d.ts +2 -13
  16. package/cjs/app/observer/top_observer.js +23 -58
  17. package/cjs/app/sanitizer.d.ts +1 -1
  18. package/cjs/app/sanitizer.js +5 -5
  19. package/cjs/app/session.d.ts +2 -20
  20. package/cjs/app/session.js +6 -65
  21. package/cjs/app/ticker.d.ts +1 -1
  22. package/cjs/common/messages.d.ts +444 -0
  23. package/cjs/common/messages.js +794 -0
  24. package/cjs/common/types.d.ts +9 -0
  25. package/cjs/common/{interaction.js → types.js} +0 -0
  26. package/cjs/common/{interaction.d.ts → webworker.d.ts} +5 -5
  27. package/cjs/common/{messages.gen.js → webworker.js} +0 -1
  28. package/cjs/index.d.ts +9 -10
  29. package/cjs/index.js +36 -47
  30. package/cjs/modules/connection.d.ts +1 -1
  31. package/cjs/modules/connection.js +2 -2
  32. package/cjs/modules/console.d.ts +1 -1
  33. package/cjs/modules/console.js +21 -7
  34. package/cjs/modules/cssrules.d.ts +1 -1
  35. package/cjs/modules/cssrules.js +14 -18
  36. package/cjs/modules/exception.d.ts +3 -3
  37. package/cjs/modules/exception.js +18 -23
  38. package/cjs/modules/img.d.ts +1 -1
  39. package/cjs/modules/img.js +26 -39
  40. package/cjs/modules/input.d.ts +1 -1
  41. package/cjs/modules/input.js +21 -21
  42. package/cjs/modules/longtasks.d.ts +2 -0
  43. package/cjs/modules/longtasks.js +26 -0
  44. package/cjs/modules/mouse.d.ts +1 -1
  45. package/cjs/modules/mouse.js +43 -50
  46. package/cjs/modules/performance.d.ts +1 -1
  47. package/cjs/modules/performance.js +2 -2
  48. package/cjs/modules/scroll.d.ts +1 -1
  49. package/cjs/modules/scroll.js +7 -16
  50. package/cjs/modules/timing.d.ts +1 -1
  51. package/cjs/modules/timing.js +26 -14
  52. package/cjs/modules/viewport.d.ts +1 -1
  53. package/cjs/modules/viewport.js +4 -4
  54. package/cjs/utils.js +7 -7
  55. package/cjs/vendors/finder/finder.js +48 -53
  56. package/lib/app/guards.d.ts +1 -2
  57. package/lib/app/guards.js +2 -4
  58. package/lib/app/index.d.ts +23 -28
  59. package/lib/app/index.js +94 -115
  60. package/lib/app/logger.js +3 -6
  61. package/lib/app/nodes.d.ts +1 -1
  62. package/lib/app/nodes.js +0 -2
  63. package/lib/app/observer/iframe_observer.d.ts +1 -1
  64. package/lib/app/observer/iframe_observer.js +3 -3
  65. package/lib/app/observer/observer.d.ts +3 -2
  66. package/lib/app/observer/observer.js +53 -51
  67. package/lib/app/observer/shadow_root_observer.d.ts +1 -1
  68. package/lib/app/observer/shadow_root_observer.js +3 -3
  69. package/lib/app/observer/top_observer.d.ts +2 -13
  70. package/lib/app/observer/top_observer.js +27 -62
  71. package/lib/app/sanitizer.d.ts +1 -1
  72. package/lib/app/sanitizer.js +7 -7
  73. package/lib/app/session.d.ts +2 -20
  74. package/lib/app/session.js +6 -65
  75. package/lib/app/ticker.d.ts +1 -1
  76. package/lib/common/messages.d.ts +444 -0
  77. package/lib/common/messages.js +790 -0
  78. package/lib/common/tsconfig.tsbuildinfo +1 -1
  79. package/lib/common/types.d.ts +9 -0
  80. package/lib/common/{interaction.js → types.js} +0 -0
  81. package/lib/common/{interaction.d.ts → webworker.d.ts} +5 -5
  82. package/lib/common/webworker.js +1 -0
  83. package/lib/index.d.ts +9 -10
  84. package/lib/index.js +49 -60
  85. package/lib/modules/connection.d.ts +1 -1
  86. package/lib/modules/connection.js +2 -2
  87. package/lib/modules/console.d.ts +1 -1
  88. package/lib/modules/console.js +22 -8
  89. package/lib/modules/cssrules.d.ts +1 -1
  90. package/lib/modules/cssrules.js +15 -19
  91. package/lib/modules/exception.d.ts +3 -3
  92. package/lib/modules/exception.js +18 -23
  93. package/lib/modules/img.d.ts +1 -1
  94. package/lib/modules/img.js +28 -41
  95. package/lib/modules/input.d.ts +1 -1
  96. package/lib/modules/input.js +23 -23
  97. package/lib/modules/longtasks.d.ts +2 -0
  98. package/lib/modules/longtasks.js +23 -0
  99. package/lib/modules/mouse.d.ts +1 -1
  100. package/lib/modules/mouse.js +46 -53
  101. package/lib/modules/performance.d.ts +1 -1
  102. package/lib/modules/performance.js +3 -3
  103. package/lib/modules/scroll.d.ts +1 -1
  104. package/lib/modules/scroll.js +8 -17
  105. package/lib/modules/timing.d.ts +1 -1
  106. package/lib/modules/timing.js +28 -16
  107. package/lib/modules/viewport.d.ts +1 -1
  108. package/lib/modules/viewport.js +4 -4
  109. package/lib/utils.js +7 -7
  110. package/lib/vendors/finder/finder.js +48 -53
  111. package/package.json +10 -27
  112. package/.eslintignore +0 -8
  113. package/.prettierignore +0 -1
  114. package/cjs/app/messages.d.ts +0 -52
  115. package/cjs/app/messages.gen.d.ts +0 -57
  116. package/cjs/app/messages.gen.js +0 -493
  117. package/cjs/app/messages.js +0 -234
  118. package/cjs/common/messages.gen.d.ts +0 -382
  119. package/cjs/modules/adoptedStyleSheets.d.ts +0 -2
  120. package/cjs/modules/adoptedStyleSheets.js +0 -127
  121. package/lib/app/messages.d.ts +0 -52
  122. package/lib/app/messages.gen.d.ts +0 -57
  123. package/lib/app/messages.gen.js +0 -434
  124. package/lib/app/messages.js +0 -181
  125. package/lib/common/messages.gen.d.ts +0 -382
  126. package/lib/common/messages.gen.js +0 -2
  127. package/lib/modules/adoptedStyleSheets.d.ts +0 -2
  128. package/lib/modules/adoptedStyleSheets.js +0 -124
@@ -0,0 +1,9 @@
1
+ export interface Writer {
2
+ uint(n: number): boolean;
3
+ int(n: number): boolean;
4
+ string(s: string): boolean;
5
+ boolean(b: boolean): boolean;
6
+ }
7
+ export interface Message {
8
+ encode(w: Writer): boolean;
9
+ }
File without changes
@@ -1,19 +1,19 @@
1
- import Message from './messages.gen.js';
2
1
  export interface Options {
3
2
  connAttemptCount?: number;
4
3
  connAttemptGap?: number;
5
4
  }
6
5
  declare type Start = {
7
- type: 'start';
6
+ type: "start";
8
7
  ingestPoint: string;
9
8
  pageNo: number;
10
9
  timestamp: number;
11
- url: string;
12
10
  } & Options;
13
11
  declare type Auth = {
14
- type: 'auth';
12
+ type: "auth";
15
13
  token: string;
16
14
  beaconSizeLimit?: number;
17
15
  };
18
- export declare type WorkerMessageData = null | 'stop' | Start | Auth | Array<Message>;
16
+ export declare type WorkerMessageData = null | "stop" | Start | Auth | Array<{
17
+ _id: number;
18
+ }>;
19
19
  export {};
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
- // Auto-generated, do not edit
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import App from './app/index.js';
1
+ import App from "./app/index.js";
2
2
  export { default as App } from './app/index.js';
3
- import * as _Messages from './app/messages.gen.js';
3
+ import * as _Messages from "./common/messages.js";
4
4
  export declare const Messages: typeof _Messages;
5
- import type { Options as AppOptions } from './app/index.js';
6
- import type { Options as ConsoleOptions } from './modules/console.js';
7
- import type { Options as ExceptionOptions } from './modules/exception.js';
8
- import type { Options as InputOptions } from './modules/input.js';
9
- import type { Options as PerformanceOptions } from './modules/performance.js';
10
- import type { Options as TimingOptions } from './modules/timing.js';
5
+ import type { Options as AppOptions } from "./app/index.js";
6
+ import type { Options as ConsoleOptions } from "./modules/console.js";
7
+ import type { Options as ExceptionOptions } from "./modules/exception.js";
8
+ import type { Options as InputOptions } from "./modules/input.js";
9
+ import type { Options as PerformanceOptions } from "./modules/performance.js";
10
+ import type { Options as TimingOptions } from "./modules/timing.js";
11
11
  import type { StartOptions } from './app/index.js';
12
12
  import type { StartPromiseReturn } from './app/index.js';
13
13
  export declare type Options = Partial<AppOptions & ConsoleOptions & ExceptionOptions & InputOptions & PerformanceOptions & TimingOptions> & {
@@ -25,11 +25,10 @@ export default class API {
25
25
  use<T>(fn: (app: App | null, options?: Options) => T): T;
26
26
  isActive(): boolean;
27
27
  start(startOpts?: Partial<StartOptions>): Promise<StartPromiseReturn>;
28
- stop(): string | undefined;
28
+ stop(): void;
29
29
  getSessionToken(): string | null | undefined;
30
30
  getSessionID(): string | null | undefined;
31
31
  sessionID(): string | null | undefined;
32
- getSessionURL(): string | undefined;
33
32
  setUserID(id: string): void;
34
33
  userID(id: string): void;
35
34
  setUserAnonymousID(id: string): void;
package/cjs/index.js CHANGED
@@ -4,8 +4,8 @@ exports.Messages = exports.App = void 0;
4
4
  const index_js_1 = require("./app/index.js");
5
5
  var index_js_2 = require("./app/index.js");
6
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");
7
+ const messages_js_1 = require("./common/messages.js");
8
+ const _Messages = require("./common/messages.js");
9
9
  exports.Messages = _Messages;
10
10
  const connection_js_1 = require("./modules/connection.js");
11
11
  const console_js_1 = require("./modules/console.js");
@@ -18,7 +18,6 @@ const performance_js_1 = require("./modules/performance.js");
18
18
  const scroll_js_1 = require("./modules/scroll.js");
19
19
  const viewport_js_1 = require("./modules/viewport.js");
20
20
  const cssrules_js_1 = require("./modules/cssrules.js");
21
- const adoptedStyleSheets_js_1 = require("./modules/adoptedStyleSheets.js");
22
21
  const utils_js_1 = require("./utils.js");
23
22
  const DOCS_SETUP = '/installation/setup-or';
24
23
  function processOptions(obj) {
@@ -28,23 +27,22 @@ function processOptions(obj) {
28
27
  }
29
28
  if (typeof obj.projectKey !== 'string') {
30
29
  if (typeof obj.projectKey !== 'number') {
31
- if (typeof obj.projectID !== 'number') {
32
- // Back compatability
30
+ if (typeof obj.projectID !== 'number') { // Back compatability
33
31
  console.error(`OpenReplay: projectKey is missing or wrong type (string is expected). Please, check ${utils_js_1.DOCS_HOST}${DOCS_SETUP} for more information.`);
34
32
  return false;
35
33
  }
36
34
  else {
37
35
  obj.projectKey = obj.projectID.toString();
38
- (0, utils_js_1.deprecationWarn)('`projectID` option', '`projectKey` option', DOCS_SETUP);
36
+ (0, utils_js_1.deprecationWarn)("`projectID` option", "`projectKey` option", DOCS_SETUP);
39
37
  }
40
38
  }
41
39
  else {
42
- console.warn('OpenReplay: projectKey is expected to have a string type.');
40
+ console.warn("OpenReplay: projectKey is expected to have a string type.");
43
41
  obj.projectKey = obj.projectKey.toString();
44
42
  }
45
43
  }
46
- if (obj.sessionToken != null) {
47
- (0, utils_js_1.deprecationWarn)('`sessionToken` option', '`sessionHash` start() option', '/');
44
+ if (typeof obj.sessionToken !== 'string' && obj.sessionToken != null) {
45
+ console.warn(`OpenReplay: invalid options argument type. Please, check documentation on ${utils_js_1.DOCS_HOST}${DOCS_SETUP}`);
48
46
  }
49
47
  return true;
50
48
  }
@@ -71,33 +69,31 @@ class API {
71
69
  return;
72
70
  }
73
71
  if (window.__OPENREPLAY__) {
74
- console.error('OpenReplay: one tracker instance has been initialised already');
72
+ console.error("OpenReplay: one tracker instance has been initialised already");
75
73
  return;
76
74
  }
77
75
  if (!options.__DISABLE_SECURE_MODE && location.protocol !== 'https:') {
78
- 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.');
76
+ 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.");
79
77
  return;
80
78
  }
81
79
  const doNotTrack = options.respectDoNotTrack &&
82
- (navigator.doNotTrack == '1' ||
80
+ (navigator.doNotTrack == '1'
83
81
  // @ts-ignore
84
- window.doNotTrack == '1');
85
- const app = (this.app =
86
- doNotTrack ||
87
- !('Map' in window) ||
88
- !('Set' in window) ||
89
- !('MutationObserver' in window) ||
90
- !('performance' in window) ||
91
- !('timing' in performance) ||
92
- !('startsWith' in String.prototype) ||
93
- !('Blob' in window) ||
94
- !('Worker' in window)
95
- ? null
96
- : new index_js_1.default(options.projectKey, options.sessionToken, options));
82
+ || window.doNotTrack == '1');
83
+ const app = this.app = doNotTrack ||
84
+ !('Map' in window) ||
85
+ !('Set' in window) ||
86
+ !('MutationObserver' in window) ||
87
+ !('performance' in window) ||
88
+ !('timing' in performance) ||
89
+ !('startsWith' in String.prototype) ||
90
+ !('Blob' in window) ||
91
+ !('Worker' in window)
92
+ ? null
93
+ : new index_js_1.default(options.projectKey, options.sessionToken, options);
97
94
  if (app !== null) {
98
95
  (0, viewport_js_1.default)(app);
99
96
  (0, cssrules_js_1.default)(app);
100
- (0, adoptedStyleSheets_js_1.default)(app);
101
97
  (0, connection_js_1.default)(app);
102
98
  (0, console_js_1.default)(app, options);
103
99
  (0, exception_js_1.default)(app, options);
@@ -127,11 +123,11 @@ class API {
127
123
  console.log("OpenReplay: browser doesn't support API required for tracking or doNotTrack is set to 1.");
128
124
  const req = new XMLHttpRequest();
129
125
  const orig = options.ingestPoint || index_js_1.DEFAULT_INGEST_POINT;
130
- req.open('POST', orig + '/v1/web/not-started');
126
+ req.open("POST", orig + "/v1/web/not-started");
131
127
  // no-cors issue only with text/plain or not-set Content-Type
132
128
  // req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
133
129
  req.send(JSON.stringify({
134
- trackerVersion: '3.6.1',
130
+ trackerVersion: '3.6.2',
135
131
  projectKey: options.projectKey,
136
132
  doNotTrack,
137
133
  // TODO: add precise reason (an exact API missing)
@@ -150,7 +146,7 @@ class API {
150
146
  start(startOpts) {
151
147
  if (!utils_js_1.IN_BROWSER) {
152
148
  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}`);
153
- return Promise.reject('Trying to start not in browser.');
149
+ return Promise.reject("Trying to start not in browser.");
154
150
  }
155
151
  if (this.app === null) {
156
152
  return Promise.reject("Browser doesn't support required api, or doNotTrack is active.");
@@ -162,10 +158,7 @@ class API {
162
158
  if (this.app === null) {
163
159
  return;
164
160
  }
165
- this.app.stop();
166
- const sessionHash = this.app.session.getSessionHash();
167
- this.app.session.reset();
168
- return sessionHash;
161
+ this.app.stop(true);
169
162
  }
170
163
  getSessionToken() {
171
164
  if (this.app === null) {
@@ -180,40 +173,36 @@ class API {
180
173
  return this.app.getSessionID();
181
174
  }
182
175
  sessionID() {
183
- (0, utils_js_1.deprecationWarn)("'sessionID' method", "'getSessionID' method", '/');
176
+ (0, utils_js_1.deprecationWarn)("'sessionID' method", "'getSessionID' method", "/");
184
177
  return this.getSessionID();
185
178
  }
186
- getSessionURL() {
187
- if (this.app === null) {
188
- return undefined;
189
- }
190
- return this.app.getSessionURL();
191
- }
192
179
  setUserID(id) {
193
180
  if (typeof id === 'string' && this.app !== null) {
194
181
  this.app.session.setUserID(id);
195
182
  }
196
183
  }
197
184
  userID(id) {
198
- (0, utils_js_1.deprecationWarn)("'userID' method", "'setUserID' method", '/');
185
+ (0, utils_js_1.deprecationWarn)("'userID' method", "'setUserID' method", "/");
199
186
  this.setUserID(id);
200
187
  }
201
188
  setUserAnonymousID(id) {
202
189
  if (typeof id === 'string' && this.app !== null) {
203
- this.app.send((0, messages_gen_js_1.UserAnonymousID)(id));
190
+ this.app.send(new messages_js_1.UserAnonymousID(id));
204
191
  }
205
192
  }
206
193
  userAnonymousID(id) {
207
- (0, utils_js_1.deprecationWarn)("'userAnonymousID' method", "'setUserAnonymousID' method", '/');
194
+ (0, utils_js_1.deprecationWarn)("'userAnonymousID' method", "'setUserAnonymousID' method", "/");
208
195
  this.setUserAnonymousID(id);
209
196
  }
210
197
  setMetadata(key, value) {
211
- if (typeof key === 'string' && typeof value === 'string' && this.app !== null) {
198
+ if (typeof key === 'string' &&
199
+ typeof value === 'string' &&
200
+ this.app !== null) {
212
201
  this.app.session.setMetadata(key, value);
213
202
  }
214
203
  }
215
204
  metadata(key, value) {
216
- (0, utils_js_1.deprecationWarn)("'metadata' method", "'setMetadata' method", '/');
205
+ (0, utils_js_1.deprecationWarn)("'metadata' method", "'setMetadata' method", "/");
217
206
  this.setMetadata(key, value);
218
207
  }
219
208
  event(key, payload, issue = false) {
@@ -228,7 +217,7 @@ class API {
228
217
  catch (e) {
229
218
  return;
230
219
  }
231
- this.app.send((0, messages_gen_js_1.RawCustomEvent)(key, payload));
220
+ this.app.send(new messages_js_1.RawCustomEvent(key, payload));
232
221
  }
233
222
  }
234
223
  }
@@ -240,7 +229,7 @@ class API {
240
229
  catch (e) {
241
230
  return;
242
231
  }
243
- this.app.send((0, messages_gen_js_1.CustomIssue)(key, payload));
232
+ this.app.send(new messages_js_1.CustomIssue(key, payload));
244
233
  }
245
234
  }
246
235
  }
@@ -1,2 +1,2 @@
1
- import App from '../app/index.js';
1
+ import App from "../app/index.js";
2
2
  export default function (app: App): void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const messages_gen_js_1 = require("../app/messages.gen.js");
3
+ const messages_js_1 = require("../common/messages.js");
4
4
  function default_1(app) {
5
5
  const connection = navigator.connection ||
6
6
  navigator.mozConnection ||
@@ -8,7 +8,7 @@ function default_1(app) {
8
8
  if (connection === undefined) {
9
9
  return;
10
10
  }
11
- const sendConnectionInformation = () => app.send((0, messages_gen_js_1.ConnectionInformation)(Math.round(connection.downlink * 1000), connection.type || 'unknown'));
11
+ const sendConnectionInformation = () => app.send(new messages_js_1.ConnectionInformation(Math.round(connection.downlink * 1000), connection.type || 'unknown'));
12
12
  sendConnectionInformation();
13
13
  connection.addEventListener('change', sendConnectionInformation);
14
14
  }
@@ -1,4 +1,4 @@
1
- import type App from '../app/index.js';
1
+ import type App from "../app/index.js";
2
2
  export interface Options {
3
3
  consoleMethods: Array<string> | null;
4
4
  consoleThrottling: number;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const guards_js_1 = require("../app/guards.js");
3
4
  const utils_js_1 = require("../utils.js");
4
- const messages_gen_js_1 = require("../app/messages.gen.js");
5
+ const messages_js_1 = require("../common/messages.js");
5
6
  const printError = utils_js_1.IN_BROWSER && 'InstallTrigger' in window // detect Firefox
6
7
  ? (e) => e.message + '\n' + e.stack
7
8
  : (e) => e.stack || e.message;
@@ -88,10 +89,11 @@ function default_1(app, opts) {
88
89
  consoleMethods,
89
90
  consoleThrottling: 30,
90
91
  }, opts);
91
- if (!Array.isArray(options.consoleMethods) || options.consoleMethods.length === 0) {
92
+ if (!Array.isArray(options.consoleMethods) ||
93
+ options.consoleMethods.length === 0) {
92
94
  return;
93
95
  }
94
- const sendConsoleLog = app.safe((level, args) => app.send((0, messages_gen_js_1.ConsoleLog)(level, printf(args))));
96
+ const sendConsoleLog = app.safe((level, args) => app.send(new messages_js_1.ConsoleLog(level, printf(args))));
95
97
  let n;
96
98
  const reset = () => {
97
99
  n = 0;
@@ -100,7 +102,7 @@ function default_1(app, opts) {
100
102
  app.ticker.attach(reset, 33, false);
101
103
  const patchConsole = (console) => options.consoleMethods.forEach((method) => {
102
104
  if (consoleMethods.indexOf(method) === -1) {
103
- app.debug.error(`OpenReplay: unsupported console method "${method}"`);
105
+ console.error(`OpenReplay: unsupported console method "${method}"`);
104
106
  return;
105
107
  }
106
108
  const fn = console[method];
@@ -112,8 +114,20 @@ function default_1(app, opts) {
112
114
  sendConsoleLog(method, args);
113
115
  };
114
116
  });
115
- const patchContext = app.safe((context) => patchConsole(context.console));
116
- patchContext(window);
117
- app.observer.attachContextCallback(patchContext);
117
+ patchConsole(window.console);
118
+ app.nodes.attachNodeCallback(app.safe(node => {
119
+ if ((0, guards_js_1.hasTag)(node, "IFRAME")) { // TODO: newContextCallback
120
+ let context = node.contentWindow;
121
+ if (context) {
122
+ patchConsole(context.console);
123
+ }
124
+ app.attachEventListener(node, "load", () => {
125
+ if (node.contentWindow !== context) {
126
+ context = node.contentWindow;
127
+ patchConsole(context.console);
128
+ }
129
+ });
130
+ }
131
+ }));
118
132
  }
119
133
  exports.default = default_1;
@@ -1,2 +1,2 @@
1
- import type App from '../app/index.js';
1
+ import type App from "../app/index.js";
2
2
  export default function (app: App | null): void;
@@ -1,43 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const messages_gen_js_1 = require("../app/messages.gen.js");
3
+ const messages_js_1 = require("../common/messages.js");
4
4
  const guards_js_1 = require("../app/guards.js");
5
5
  function default_1(app) {
6
6
  if (app === null) {
7
7
  return;
8
8
  }
9
9
  if (!window.CSSStyleSheet) {
10
- app.send((0, messages_gen_js_1.TechnicalInfo)('no_stylesheet_prototype_in_window', ''));
10
+ app.send(new messages_js_1.TechnicalInfo("no_stylesheet_prototype_in_window", ""));
11
11
  return;
12
12
  }
13
13
  const processOperation = app.safe((stylesheet, index, rule) => {
14
14
  const sendMessage = typeof rule === 'string'
15
- ? (nodeID) => app.send((0, messages_gen_js_1.CSSInsertRuleURLBased)(nodeID, rule, index, app.getBaseHref()))
16
- : (nodeID) => app.send((0, messages_gen_js_1.CSSDeleteRule)(nodeID, index));
15
+ ? (nodeID) => app.send(new messages_js_1.CSSInsertRuleURLBased(nodeID, rule, index, app.getBaseHref()))
16
+ : (nodeID) => app.send(new messages_js_1.CSSDeleteRule(nodeID, index));
17
17
  // TODO: Extend messages to maintain nested rules (CSSGroupingRule prototype, as well as CSSKeyframesRule)
18
18
  if (stylesheet.ownerNode == null) {
19
- throw new Error('Owner Node not found');
19
+ throw new Error("Owner Node not found");
20
20
  }
21
21
  const nodeID = app.nodes.getID(stylesheet.ownerNode);
22
22
  if (nodeID !== undefined) {
23
23
  sendMessage(nodeID);
24
24
  } // else error?
25
25
  });
26
- const patchContext = (context) => {
27
- const { insertRule, deleteRule } = context.CSSStyleSheet.prototype;
28
- context.CSSStyleSheet.prototype.insertRule = function (rule, index = 0) {
29
- processOperation(this, index, rule);
30
- return insertRule.call(this, rule, index);
31
- };
32
- context.CSSStyleSheet.prototype.deleteRule = function (index) {
33
- processOperation(this, index);
34
- return deleteRule.call(this, index);
35
- };
26
+ const { insertRule, deleteRule } = CSSStyleSheet.prototype;
27
+ CSSStyleSheet.prototype.insertRule = function (rule, index = 0) {
28
+ processOperation(this, index, rule);
29
+ return insertRule.call(this, rule, index);
30
+ };
31
+ CSSStyleSheet.prototype.deleteRule = function (index) {
32
+ processOperation(this, index);
33
+ return deleteRule.call(this, index);
36
34
  };
37
- patchContext(window);
38
- app.observer.attachContextCallback(patchContext);
39
35
  app.nodes.attachNodeCallback((node) => {
40
- if (!(0, guards_js_1.hasTag)(node, 'STYLE') || !node.sheet) {
36
+ if (!(0, guards_js_1.hasTag)(node, "STYLE") || !node.sheet) {
41
37
  return;
42
38
  }
43
39
  if (node.textContent !== null && node.textContent.trim().length > 0) {
@@ -1,5 +1,5 @@
1
- import type App from '../app/index.js';
2
- import type Message from '../app/messages.gen.js';
1
+ import type App from "../app/index.js";
2
+ import type Message from "../common/messages.js";
3
3
  export interface Options {
4
4
  captureExceptions: boolean;
5
5
  }
@@ -11,6 +11,6 @@ interface StackFrame {
11
11
  source?: string;
12
12
  }
13
13
  export declare function getExceptionMessage(error: Error, fallbackStack: Array<StackFrame>): Message;
14
- export declare function getExceptionMessageFromEvent(e: ErrorEvent | PromiseRejectionEvent, context?: typeof globalThis): Message | null;
14
+ export declare function getExceptionMessageFromEvent(e: ErrorEvent | PromiseRejectionEvent): Message | null;
15
15
  export default function (app: App, opts: Partial<Options>): void;
16
16
  export {};
@@ -1,29 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getExceptionMessageFromEvent = exports.getExceptionMessage = void 0;
4
- const messages_gen_js_1 = require("../app/messages.gen.js");
4
+ const messages_js_1 = require("../common/messages.js");
5
5
  const error_stack_parser_1 = require("error-stack-parser");
6
6
  function getDefaultStack(e) {
7
- return [
8
- {
7
+ return [{
9
8
  columnNumber: e.colno,
10
9
  lineNumber: e.lineno,
11
10
  fileName: e.filename,
12
- functionName: '',
13
- source: '',
14
- },
15
- ];
11
+ functionName: "",
12
+ source: "",
13
+ }];
16
14
  }
17
15
  function getExceptionMessage(error, fallbackStack) {
18
16
  let stack = fallbackStack;
19
17
  try {
20
18
  stack = error_stack_parser_1.default.parse(error);
21
19
  }
22
- catch (e) { }
23
- return (0, messages_gen_js_1.JSException)(error.name, error.message, JSON.stringify(stack));
20
+ catch (e) {
21
+ }
22
+ return new messages_js_1.JSException(error.name, error.message, JSON.stringify(stack));
24
23
  }
25
24
  exports.getExceptionMessage = getExceptionMessage;
26
- function getExceptionMessageFromEvent(e, context = window) {
25
+ function getExceptionMessageFromEvent(e) {
27
26
  if (e instanceof ErrorEvent) {
28
27
  if (e.error instanceof Error) {
29
28
  return getExceptionMessage(e.error, getDefaultStack(e));
@@ -34,10 +33,10 @@ function getExceptionMessageFromEvent(e, context = window) {
34
33
  name = 'Error';
35
34
  message = e.message;
36
35
  }
37
- return (0, messages_gen_js_1.JSException)(name, message, JSON.stringify(getDefaultStack(e)));
36
+ return new messages_js_1.JSException(name, message, JSON.stringify(getDefaultStack(e)));
38
37
  }
39
38
  }
40
- else if ('PromiseRejectionEvent' in context && e instanceof context.PromiseRejectionEvent) {
39
+ else if ('PromiseRejectionEvent' in window && e instanceof PromiseRejectionEvent) {
41
40
  if (e.reason instanceof Error) {
42
41
  return getExceptionMessage(e.reason, []);
43
42
  }
@@ -49,7 +48,7 @@ function getExceptionMessageFromEvent(e, context = window) {
49
48
  catch (_) {
50
49
  message = String(e.reason);
51
50
  }
52
- return (0, messages_gen_js_1.JSException)('Unhandled Promise Rejection', message, '[]');
51
+ return new messages_js_1.JSException('Unhandled Promise Rejection', message, '[]');
53
52
  }
54
53
  }
55
54
  return null;
@@ -59,19 +58,15 @@ function default_1(app, opts) {
59
58
  const options = Object.assign({
60
59
  captureExceptions: true,
61
60
  }, opts);
62
- function patchContext(context) {
63
- function handler(e) {
64
- const msg = getExceptionMessageFromEvent(e, context);
61
+ if (options.captureExceptions) {
62
+ const handler = (e) => {
63
+ const msg = getExceptionMessageFromEvent(e);
65
64
  if (msg != null) {
66
65
  app.send(msg);
67
66
  }
68
- }
69
- app.attachEventListener(context, 'unhandledrejection', handler);
70
- app.attachEventListener(context, 'error', handler);
71
- }
72
- if (options.captureExceptions) {
73
- app.observer.attachContextCallback(patchContext);
74
- patchContext(window);
67
+ };
68
+ app.attachEventListener(window, 'unhandledrejection', (e) => handler(e));
69
+ app.attachEventListener(window, 'error', (e) => handler(e));
75
70
  }
76
71
  }
77
72
  exports.default = default_1;
@@ -1,2 +1,2 @@
1
- import type App from '../app/index.js';
1
+ import type App from "../app/index.js";
2
2
  export default function (app: App): void;