@naylence/runtime 0.3.5-test.940 → 0.3.5-test.942

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.
@@ -6,6 +6,7 @@ import { BaseAsyncConnector, } from './base-async-connector.js';
6
6
  import { FameTransportClose } from '../errors/errors.js';
7
7
  import { getLogger } from '../util/logging.js';
8
8
  import { BoundedAsyncQueue, QueueFullError, } from '../util/bounded-async-queue.js';
9
+ import { ConnectorState } from '@naylence/core';
9
10
  const logger = getLogger('naylence.fame.connector.inpage_connector');
10
11
  export const INPAGE_CONNECTOR_TYPE = 'inpage-connector';
11
12
  const DEFAULT_CHANNEL = 'naylence-fabric';
@@ -64,6 +65,7 @@ export class InPageConnector extends BaseAsyncConnector {
64
65
  ensureBrowserEnvironment();
65
66
  super(baseConfig);
66
67
  this.listenerRegistered = false;
68
+ this.visibilityChangeListenerRegistered = false;
67
69
  this.channelName =
68
70
  typeof config.channelName === 'string' && config.channelName.trim().length > 0
69
71
  ? config.channelName.trim()
@@ -151,6 +153,92 @@ export class InPageConnector extends BaseAsyncConnector {
151
153
  };
152
154
  getSharedBus().addEventListener(this.channelName, this.onMsg);
153
155
  this.listenerRegistered = true;
156
+ // Setup visibility change monitoring
157
+ this.visibilityChangeHandler = () => {
158
+ const isHidden = document.hidden;
159
+ logger.debug('inpage_visibility_changed', {
160
+ channel: this.channelName,
161
+ connector_id: this.connectorId,
162
+ visibility: isHidden ? 'hidden' : 'visible',
163
+ timestamp: new Date().toISOString(),
164
+ });
165
+ // Pause/resume connector based on visibility
166
+ if (isHidden && this.state === ConnectorState.STARTED) {
167
+ this.pause().catch((err) => {
168
+ logger.warning('inpage_pause_failed', {
169
+ channel: this.channelName,
170
+ connector_id: this.connectorId,
171
+ error: err instanceof Error ? err.message : String(err),
172
+ });
173
+ });
174
+ }
175
+ else if (!isHidden && this.state === ConnectorState.PAUSED) {
176
+ this.resume().catch((err) => {
177
+ logger.warning('inpage_resume_failed', {
178
+ channel: this.channelName,
179
+ connector_id: this.connectorId,
180
+ error: err instanceof Error ? err.message : String(err),
181
+ });
182
+ });
183
+ }
184
+ };
185
+ if (typeof document !== 'undefined') {
186
+ document.addEventListener('visibilitychange', this.visibilityChangeHandler);
187
+ this.visibilityChangeListenerRegistered = true;
188
+ // Track page lifecycle events to detect browser unload/discard
189
+ if (typeof window !== 'undefined') {
190
+ const lifecycleLogger = (event) => {
191
+ logger.info('inpage_page_lifecycle', {
192
+ channel: this.channelName,
193
+ connector_id: this.connectorId,
194
+ event_type: event.type,
195
+ visibility_state: document.visibilityState,
196
+ timestamp: new Date().toISOString(),
197
+ });
198
+ };
199
+ window.addEventListener('beforeunload', lifecycleLogger);
200
+ window.addEventListener('unload', lifecycleLogger);
201
+ window.addEventListener('pagehide', lifecycleLogger);
202
+ window.addEventListener('pageshow', lifecycleLogger);
203
+ document.addEventListener('freeze', lifecycleLogger);
204
+ document.addEventListener('resume', lifecycleLogger);
205
+ }
206
+ // Log initial state with detailed visibility info
207
+ logger.debug('inpage_initial_visibility', {
208
+ channel: this.channelName,
209
+ connector_id: this.connectorId,
210
+ visibility: document.hidden ? 'hidden' : 'visible',
211
+ document_hidden: document.hidden,
212
+ visibility_state: document.visibilityState,
213
+ has_focus: document.hasFocus(),
214
+ timestamp: new Date().toISOString(),
215
+ });
216
+ }
217
+ }
218
+ /**
219
+ * Override start() to check initial visibility state
220
+ */
221
+ async start(inboundHandler) {
222
+ await super.start(inboundHandler);
223
+ // After transitioning to STARTED, check if tab is already hidden
224
+ if (typeof document !== 'undefined' && document.hidden) {
225
+ logger.debug('inpage_start_in_hidden_tab', {
226
+ channel: this.channelName,
227
+ connector_id: this.connectorId,
228
+ document_hidden: document.hidden,
229
+ visibility_state: document.visibilityState,
230
+ has_focus: document.hasFocus(),
231
+ timestamp: new Date().toISOString(),
232
+ });
233
+ // Immediately pause if tab is hidden at start time
234
+ await this.pause().catch((err) => {
235
+ logger.warning('inpage_initial_pause_failed', {
236
+ channel: this.channelName,
237
+ connector_id: this.connectorId,
238
+ error: err instanceof Error ? err.message : String(err),
239
+ });
240
+ });
241
+ }
154
242
  }
155
243
  // Allow listeners to feed envelopes directly into the in-page receive queue.
156
244
  async pushToReceive(rawOrEnvelope) {
@@ -200,6 +288,11 @@ export class InPageConnector extends BaseAsyncConnector {
200
288
  getSharedBus().removeEventListener(this.channelName, this.onMsg);
201
289
  this.listenerRegistered = false;
202
290
  }
291
+ if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
292
+ document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
293
+ this.visibilityChangeListenerRegistered = false;
294
+ this.visibilityChangeHandler = undefined;
295
+ }
203
296
  const closeCode = typeof code === 'number' ? code : 1000;
204
297
  const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
205
298
  const shutdownError = new FameTransportClose(closeReason, closeCode);
@@ -385,7 +385,7 @@ export class UpstreamSessionManager extends TaskSpawner {
385
385
  this.currentStopSubtasks = null;
386
386
  await Promise.allSettled(tasks.map((task) => task.promise));
387
387
  if (this.connector) {
388
- logger.info('upstream_stopping_old_connector', {
388
+ logger.debug('upstream_stopping_old_connector', {
389
389
  connect_epoch: this.connectEpoch,
390
390
  target_system_id: this.targetSystemId,
391
391
  timestamp: new Date().toISOString(),
@@ -396,7 +396,7 @@ export class UpstreamSessionManager extends TaskSpawner {
396
396
  error: err instanceof Error ? err.message : String(err),
397
397
  });
398
398
  });
399
- logger.info('upstream_old_connector_stopped', {
399
+ logger.debug('upstream_old_connector_stopped', {
400
400
  connect_epoch: this.connectEpoch,
401
401
  target_system_id: this.targetSystemId,
402
402
  timestamp: new Date().toISOString(),
@@ -1,7 +1,7 @@
1
1
  // This file is auto-generated during build - do not edit manually
2
- // Generated from package.json version: 0.3.5-test.940
2
+ // Generated from package.json version: 0.3.5-test.942
3
3
  /**
4
4
  * The package version, injected at build time.
5
5
  * @internal
6
6
  */
7
- export const VERSION = '0.3.5-test.940';
7
+ export const VERSION = '0.3.5-test.942';
@@ -14,12 +14,12 @@ var fastify = require('fastify');
14
14
  var websocketPlugin = require('@fastify/websocket');
15
15
 
16
16
  // This file is auto-generated during build - do not edit manually
17
- // Generated from package.json version: 0.3.5-test.940
17
+ // Generated from package.json version: 0.3.5-test.942
18
18
  /**
19
19
  * The package version, injected at build time.
20
20
  * @internal
21
21
  */
22
- const VERSION = '0.3.5-test.940';
22
+ const VERSION = '0.3.5-test.942';
23
23
 
24
24
  /**
25
25
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -9909,6 +9909,24 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9909
9909
  if (typeof document !== 'undefined') {
9910
9910
  document.addEventListener('visibilitychange', this.visibilityChangeHandler);
9911
9911
  this.visibilityChangeListenerRegistered = true;
9912
+ // Track page lifecycle events to detect browser unload/discard
9913
+ if (typeof window !== 'undefined') {
9914
+ const lifecycleLogger = (event) => {
9915
+ logger$_.info('broadcast_channel_page_lifecycle', {
9916
+ channel: this.channelName,
9917
+ connector_id: this.connectorId,
9918
+ event_type: event.type,
9919
+ visibility_state: document.visibilityState,
9920
+ timestamp: new Date().toISOString(),
9921
+ });
9922
+ };
9923
+ window.addEventListener('beforeunload', lifecycleLogger);
9924
+ window.addEventListener('unload', lifecycleLogger);
9925
+ window.addEventListener('pagehide', lifecycleLogger);
9926
+ window.addEventListener('pageshow', lifecycleLogger);
9927
+ document.addEventListener('freeze', lifecycleLogger);
9928
+ document.addEventListener('resume', lifecycleLogger);
9929
+ }
9912
9930
  // Log initial state with detailed visibility info
9913
9931
  logger$_.debug('broadcast_channel_initial_visibility', {
9914
9932
  channel: this.channelName,
@@ -9917,6 +9935,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9917
9935
  document_hidden: document.hidden,
9918
9936
  visibility_state: document.visibilityState,
9919
9937
  has_focus: document.hasFocus(),
9938
+ timestamp: new Date().toISOString(),
9920
9939
  });
9921
9940
  }
9922
9941
  }
@@ -10674,7 +10693,7 @@ class UpstreamSessionManager extends TaskSpawner {
10674
10693
  this.currentStopSubtasks = null;
10675
10694
  await Promise.allSettled(tasks.map((task) => task.promise));
10676
10695
  if (this.connector) {
10677
- logger$Z.info('upstream_stopping_old_connector', {
10696
+ logger$Z.debug('upstream_stopping_old_connector', {
10678
10697
  connect_epoch: this.connectEpoch,
10679
10698
  target_system_id: this.targetSystemId,
10680
10699
  timestamp: new Date().toISOString(),
@@ -10685,7 +10704,7 @@ class UpstreamSessionManager extends TaskSpawner {
10685
10704
  error: err instanceof Error ? err.message : String(err),
10686
10705
  });
10687
10706
  });
10688
- logger$Z.info('upstream_old_connector_stopped', {
10707
+ logger$Z.debug('upstream_old_connector_stopped', {
10689
10708
  connect_epoch: this.connectEpoch,
10690
10709
  target_system_id: this.targetSystemId,
10691
10710
  timestamp: new Date().toISOString(),
@@ -20229,6 +20248,7 @@ class InPageConnector extends BaseAsyncConnector {
20229
20248
  ensureBrowserEnvironment$2();
20230
20249
  super(baseConfig);
20231
20250
  this.listenerRegistered = false;
20251
+ this.visibilityChangeListenerRegistered = false;
20232
20252
  this.channelName =
20233
20253
  typeof config.channelName === 'string' && config.channelName.trim().length > 0
20234
20254
  ? config.channelName.trim()
@@ -20316,6 +20336,92 @@ class InPageConnector extends BaseAsyncConnector {
20316
20336
  };
20317
20337
  getSharedBus$1().addEventListener(this.channelName, this.onMsg);
20318
20338
  this.listenerRegistered = true;
20339
+ // Setup visibility change monitoring
20340
+ this.visibilityChangeHandler = () => {
20341
+ const isHidden = document.hidden;
20342
+ logger$G.debug('inpage_visibility_changed', {
20343
+ channel: this.channelName,
20344
+ connector_id: this.connectorId,
20345
+ visibility: isHidden ? 'hidden' : 'visible',
20346
+ timestamp: new Date().toISOString(),
20347
+ });
20348
+ // Pause/resume connector based on visibility
20349
+ if (isHidden && this.state === core.ConnectorState.STARTED) {
20350
+ this.pause().catch((err) => {
20351
+ logger$G.warning('inpage_pause_failed', {
20352
+ channel: this.channelName,
20353
+ connector_id: this.connectorId,
20354
+ error: err instanceof Error ? err.message : String(err),
20355
+ });
20356
+ });
20357
+ }
20358
+ else if (!isHidden && this.state === core.ConnectorState.PAUSED) {
20359
+ this.resume().catch((err) => {
20360
+ logger$G.warning('inpage_resume_failed', {
20361
+ channel: this.channelName,
20362
+ connector_id: this.connectorId,
20363
+ error: err instanceof Error ? err.message : String(err),
20364
+ });
20365
+ });
20366
+ }
20367
+ };
20368
+ if (typeof document !== 'undefined') {
20369
+ document.addEventListener('visibilitychange', this.visibilityChangeHandler);
20370
+ this.visibilityChangeListenerRegistered = true;
20371
+ // Track page lifecycle events to detect browser unload/discard
20372
+ if (typeof window !== 'undefined') {
20373
+ const lifecycleLogger = (event) => {
20374
+ logger$G.info('inpage_page_lifecycle', {
20375
+ channel: this.channelName,
20376
+ connector_id: this.connectorId,
20377
+ event_type: event.type,
20378
+ visibility_state: document.visibilityState,
20379
+ timestamp: new Date().toISOString(),
20380
+ });
20381
+ };
20382
+ window.addEventListener('beforeunload', lifecycleLogger);
20383
+ window.addEventListener('unload', lifecycleLogger);
20384
+ window.addEventListener('pagehide', lifecycleLogger);
20385
+ window.addEventListener('pageshow', lifecycleLogger);
20386
+ document.addEventListener('freeze', lifecycleLogger);
20387
+ document.addEventListener('resume', lifecycleLogger);
20388
+ }
20389
+ // Log initial state with detailed visibility info
20390
+ logger$G.debug('inpage_initial_visibility', {
20391
+ channel: this.channelName,
20392
+ connector_id: this.connectorId,
20393
+ visibility: document.hidden ? 'hidden' : 'visible',
20394
+ document_hidden: document.hidden,
20395
+ visibility_state: document.visibilityState,
20396
+ has_focus: document.hasFocus(),
20397
+ timestamp: new Date().toISOString(),
20398
+ });
20399
+ }
20400
+ }
20401
+ /**
20402
+ * Override start() to check initial visibility state
20403
+ */
20404
+ async start(inboundHandler) {
20405
+ await super.start(inboundHandler);
20406
+ // After transitioning to STARTED, check if tab is already hidden
20407
+ if (typeof document !== 'undefined' && document.hidden) {
20408
+ logger$G.debug('inpage_start_in_hidden_tab', {
20409
+ channel: this.channelName,
20410
+ connector_id: this.connectorId,
20411
+ document_hidden: document.hidden,
20412
+ visibility_state: document.visibilityState,
20413
+ has_focus: document.hasFocus(),
20414
+ timestamp: new Date().toISOString(),
20415
+ });
20416
+ // Immediately pause if tab is hidden at start time
20417
+ await this.pause().catch((err) => {
20418
+ logger$G.warning('inpage_initial_pause_failed', {
20419
+ channel: this.channelName,
20420
+ connector_id: this.connectorId,
20421
+ error: err instanceof Error ? err.message : String(err),
20422
+ });
20423
+ });
20424
+ }
20319
20425
  }
20320
20426
  // Allow listeners to feed envelopes directly into the in-page receive queue.
20321
20427
  async pushToReceive(rawOrEnvelope) {
@@ -20365,6 +20471,11 @@ class InPageConnector extends BaseAsyncConnector {
20365
20471
  getSharedBus$1().removeEventListener(this.channelName, this.onMsg);
20366
20472
  this.listenerRegistered = false;
20367
20473
  }
20474
+ if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
20475
+ document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
20476
+ this.visibilityChangeListenerRegistered = false;
20477
+ this.visibilityChangeHandler = undefined;
20478
+ }
20368
20479
  const closeCode = typeof code === 'number' ? code : 1000;
20369
20480
  const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
20370
20481
  const shutdownError = new FameTransportClose(closeReason, closeCode);
@@ -13,12 +13,12 @@ import fastify from 'fastify';
13
13
  import websocketPlugin from '@fastify/websocket';
14
14
 
15
15
  // This file is auto-generated during build - do not edit manually
16
- // Generated from package.json version: 0.3.5-test.940
16
+ // Generated from package.json version: 0.3.5-test.942
17
17
  /**
18
18
  * The package version, injected at build time.
19
19
  * @internal
20
20
  */
21
- const VERSION = '0.3.5-test.940';
21
+ const VERSION = '0.3.5-test.942';
22
22
 
23
23
  /**
24
24
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -9908,6 +9908,24 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9908
9908
  if (typeof document !== 'undefined') {
9909
9909
  document.addEventListener('visibilitychange', this.visibilityChangeHandler);
9910
9910
  this.visibilityChangeListenerRegistered = true;
9911
+ // Track page lifecycle events to detect browser unload/discard
9912
+ if (typeof window !== 'undefined') {
9913
+ const lifecycleLogger = (event) => {
9914
+ logger$_.info('broadcast_channel_page_lifecycle', {
9915
+ channel: this.channelName,
9916
+ connector_id: this.connectorId,
9917
+ event_type: event.type,
9918
+ visibility_state: document.visibilityState,
9919
+ timestamp: new Date().toISOString(),
9920
+ });
9921
+ };
9922
+ window.addEventListener('beforeunload', lifecycleLogger);
9923
+ window.addEventListener('unload', lifecycleLogger);
9924
+ window.addEventListener('pagehide', lifecycleLogger);
9925
+ window.addEventListener('pageshow', lifecycleLogger);
9926
+ document.addEventListener('freeze', lifecycleLogger);
9927
+ document.addEventListener('resume', lifecycleLogger);
9928
+ }
9911
9929
  // Log initial state with detailed visibility info
9912
9930
  logger$_.debug('broadcast_channel_initial_visibility', {
9913
9931
  channel: this.channelName,
@@ -9916,6 +9934,7 @@ let BroadcastChannelConnector$2 = class BroadcastChannelConnector extends BaseAs
9916
9934
  document_hidden: document.hidden,
9917
9935
  visibility_state: document.visibilityState,
9918
9936
  has_focus: document.hasFocus(),
9937
+ timestamp: new Date().toISOString(),
9919
9938
  });
9920
9939
  }
9921
9940
  }
@@ -10673,7 +10692,7 @@ class UpstreamSessionManager extends TaskSpawner {
10673
10692
  this.currentStopSubtasks = null;
10674
10693
  await Promise.allSettled(tasks.map((task) => task.promise));
10675
10694
  if (this.connector) {
10676
- logger$Z.info('upstream_stopping_old_connector', {
10695
+ logger$Z.debug('upstream_stopping_old_connector', {
10677
10696
  connect_epoch: this.connectEpoch,
10678
10697
  target_system_id: this.targetSystemId,
10679
10698
  timestamp: new Date().toISOString(),
@@ -10684,7 +10703,7 @@ class UpstreamSessionManager extends TaskSpawner {
10684
10703
  error: err instanceof Error ? err.message : String(err),
10685
10704
  });
10686
10705
  });
10687
- logger$Z.info('upstream_old_connector_stopped', {
10706
+ logger$Z.debug('upstream_old_connector_stopped', {
10688
10707
  connect_epoch: this.connectEpoch,
10689
10708
  target_system_id: this.targetSystemId,
10690
10709
  timestamp: new Date().toISOString(),
@@ -20228,6 +20247,7 @@ class InPageConnector extends BaseAsyncConnector {
20228
20247
  ensureBrowserEnvironment$2();
20229
20248
  super(baseConfig);
20230
20249
  this.listenerRegistered = false;
20250
+ this.visibilityChangeListenerRegistered = false;
20231
20251
  this.channelName =
20232
20252
  typeof config.channelName === 'string' && config.channelName.trim().length > 0
20233
20253
  ? config.channelName.trim()
@@ -20315,6 +20335,92 @@ class InPageConnector extends BaseAsyncConnector {
20315
20335
  };
20316
20336
  getSharedBus$1().addEventListener(this.channelName, this.onMsg);
20317
20337
  this.listenerRegistered = true;
20338
+ // Setup visibility change monitoring
20339
+ this.visibilityChangeHandler = () => {
20340
+ const isHidden = document.hidden;
20341
+ logger$G.debug('inpage_visibility_changed', {
20342
+ channel: this.channelName,
20343
+ connector_id: this.connectorId,
20344
+ visibility: isHidden ? 'hidden' : 'visible',
20345
+ timestamp: new Date().toISOString(),
20346
+ });
20347
+ // Pause/resume connector based on visibility
20348
+ if (isHidden && this.state === ConnectorState.STARTED) {
20349
+ this.pause().catch((err) => {
20350
+ logger$G.warning('inpage_pause_failed', {
20351
+ channel: this.channelName,
20352
+ connector_id: this.connectorId,
20353
+ error: err instanceof Error ? err.message : String(err),
20354
+ });
20355
+ });
20356
+ }
20357
+ else if (!isHidden && this.state === ConnectorState.PAUSED) {
20358
+ this.resume().catch((err) => {
20359
+ logger$G.warning('inpage_resume_failed', {
20360
+ channel: this.channelName,
20361
+ connector_id: this.connectorId,
20362
+ error: err instanceof Error ? err.message : String(err),
20363
+ });
20364
+ });
20365
+ }
20366
+ };
20367
+ if (typeof document !== 'undefined') {
20368
+ document.addEventListener('visibilitychange', this.visibilityChangeHandler);
20369
+ this.visibilityChangeListenerRegistered = true;
20370
+ // Track page lifecycle events to detect browser unload/discard
20371
+ if (typeof window !== 'undefined') {
20372
+ const lifecycleLogger = (event) => {
20373
+ logger$G.info('inpage_page_lifecycle', {
20374
+ channel: this.channelName,
20375
+ connector_id: this.connectorId,
20376
+ event_type: event.type,
20377
+ visibility_state: document.visibilityState,
20378
+ timestamp: new Date().toISOString(),
20379
+ });
20380
+ };
20381
+ window.addEventListener('beforeunload', lifecycleLogger);
20382
+ window.addEventListener('unload', lifecycleLogger);
20383
+ window.addEventListener('pagehide', lifecycleLogger);
20384
+ window.addEventListener('pageshow', lifecycleLogger);
20385
+ document.addEventListener('freeze', lifecycleLogger);
20386
+ document.addEventListener('resume', lifecycleLogger);
20387
+ }
20388
+ // Log initial state with detailed visibility info
20389
+ logger$G.debug('inpage_initial_visibility', {
20390
+ channel: this.channelName,
20391
+ connector_id: this.connectorId,
20392
+ visibility: document.hidden ? 'hidden' : 'visible',
20393
+ document_hidden: document.hidden,
20394
+ visibility_state: document.visibilityState,
20395
+ has_focus: document.hasFocus(),
20396
+ timestamp: new Date().toISOString(),
20397
+ });
20398
+ }
20399
+ }
20400
+ /**
20401
+ * Override start() to check initial visibility state
20402
+ */
20403
+ async start(inboundHandler) {
20404
+ await super.start(inboundHandler);
20405
+ // After transitioning to STARTED, check if tab is already hidden
20406
+ if (typeof document !== 'undefined' && document.hidden) {
20407
+ logger$G.debug('inpage_start_in_hidden_tab', {
20408
+ channel: this.channelName,
20409
+ connector_id: this.connectorId,
20410
+ document_hidden: document.hidden,
20411
+ visibility_state: document.visibilityState,
20412
+ has_focus: document.hasFocus(),
20413
+ timestamp: new Date().toISOString(),
20414
+ });
20415
+ // Immediately pause if tab is hidden at start time
20416
+ await this.pause().catch((err) => {
20417
+ logger$G.warning('inpage_initial_pause_failed', {
20418
+ channel: this.channelName,
20419
+ connector_id: this.connectorId,
20420
+ error: err instanceof Error ? err.message : String(err),
20421
+ });
20422
+ });
20423
+ }
20318
20424
  }
20319
20425
  // Allow listeners to feed envelopes directly into the in-page receive queue.
20320
20426
  async pushToReceive(rawOrEnvelope) {
@@ -20364,6 +20470,11 @@ class InPageConnector extends BaseAsyncConnector {
20364
20470
  getSharedBus$1().removeEventListener(this.channelName, this.onMsg);
20365
20471
  this.listenerRegistered = false;
20366
20472
  }
20473
+ if (this.visibilityChangeListenerRegistered && this.visibilityChangeHandler && typeof document !== 'undefined') {
20474
+ document.removeEventListener('visibilitychange', this.visibilityChangeHandler);
20475
+ this.visibilityChangeListenerRegistered = false;
20476
+ this.visibilityChangeHandler = undefined;
20477
+ }
20367
20478
  const closeCode = typeof code === 'number' ? code : 1000;
20368
20479
  const closeReason = typeof reason === 'string' && reason.length > 0 ? reason : 'closed';
20369
20480
  const shutdownError = new FameTransportClose(closeReason, closeCode);