@chromahq/core 1.0.58 → 1.0.62

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.
@@ -71,7 +71,7 @@ let AppEventBus = class {
71
71
  if (matching.length === 0) {
72
72
  return;
73
73
  }
74
- const results = await Promise.allSettled(
74
+ await Promise.allSettled(
75
75
  matching.map(async (sub) => {
76
76
  try {
77
77
  await sub.handler(payload);
@@ -84,12 +84,6 @@ let AppEventBus = class {
84
84
  }
85
85
  })
86
86
  );
87
- const failed = results.filter((r) => r.status === "rejected").length;
88
- if (failed > 0) {
89
- console.warn(
90
- `[AppEventBus] ${failed}/${matching.length} handler(s) failed for event "${eventName}"`
91
- );
92
- }
93
87
  }
94
88
  // ─────────────────────────────────────────────────────────────────────────
95
89
  // Utilities
@@ -301,16 +295,11 @@ class NonceService {
301
295
  */
302
296
  cleanup() {
303
297
  const now = Date.now();
304
- let removed = 0;
305
298
  this.nonceStore.forEach((entry, nonce) => {
306
299
  if (now > entry.expiresAt) {
307
300
  this.nonceStore.delete(nonce);
308
- removed++;
309
301
  }
310
302
  });
311
- if (removed > 0) {
312
- console.log(`[NonceService] Cleaned up ${removed} expired nonces`);
313
- }
314
303
  }
315
304
  /**
316
305
  * Destroy the service (stop cleanup interval)
@@ -461,10 +450,8 @@ const _PopupVisibilityService = class _PopupVisibilityService {
461
450
  onPortConnected() {
462
451
  const wasVisible = this.isPopupVisible();
463
452
  this.connectedPortCount++;
464
- console.log(`[PopupVisibilityService] Port connected, count: ${this.connectedPortCount}`);
465
453
  if (!wasVisible && this.isPopupVisible()) {
466
454
  this.lastVisibilityChangeAt = Date.now();
467
- console.log("[PopupVisibilityService] Popup became visible, notifying listeners");
468
455
  this.notifyListeners(true);
469
456
  }
470
457
  }
@@ -475,10 +462,8 @@ const _PopupVisibilityService = class _PopupVisibilityService {
475
462
  onPortDisconnected() {
476
463
  const wasVisible = this.isPopupVisible();
477
464
  this.connectedPortCount = Math.max(0, this.connectedPortCount - 1);
478
- console.log(`[PopupVisibilityService] Port disconnected, count: ${this.connectedPortCount}`);
479
465
  if (wasVisible && !this.isPopupVisible()) {
480
466
  this.lastVisibilityChangeAt = Date.now();
481
- console.log("[PopupVisibilityService] Popup became hidden, notifying listeners");
482
467
  this.notifyListeners(false);
483
468
  }
484
469
  }
@@ -535,24 +520,18 @@ function setupEarlyListener(portName = DEFAULT_PORT_NAME$1) {
535
520
  if (portsClaimed && onPortConnectCallback) {
536
521
  onPortConnectCallback(port);
537
522
  } else {
538
- console.log(`[EarlyListener] Captured early port connection: ${port.name}`);
539
523
  earlyPorts.push(port);
540
524
  }
541
525
  });
542
- console.log(`[EarlyListener] Early connection listener registered for port: ${portName}`);
543
526
  }
544
527
  function claimEarlyPorts(onConnect) {
545
528
  if (portsClaimed) {
546
- console.warn("[EarlyListener] Ports already claimed, returning empty array");
547
529
  return [];
548
530
  }
549
531
  portsClaimed = true;
550
532
  onPortConnectCallback = onConnect;
551
533
  const captured = [...earlyPorts];
552
534
  earlyPorts.length = 0;
553
- if (captured.length > 0) {
554
- console.log(`[EarlyListener] Claimed ${captured.length} early port(s)`);
555
- }
556
535
  return captured;
557
536
  }
558
537
  function isEarlyListenerSetup() {
@@ -667,7 +646,7 @@ const _BridgeRuntimeManager = class _BridgeRuntimeManager {
667
646
  if (!this.isValidPort(port)) {
668
647
  return;
669
648
  }
670
- this.logger.info(`\u{1F4E1} Port connected: ${port.name}`);
649
+ this.logger.debug(`\u{1F4E1} Port connected: ${port.name}`);
671
650
  this.setupMessageHandler(port);
672
651
  if (chrome.runtime.lastError) {
673
652
  this.logger.warn(`Runtime error during port setup: ${chrome.runtime.lastError.message}`);
@@ -684,7 +663,7 @@ const _BridgeRuntimeManager = class _BridgeRuntimeManager {
684
663
  if (isEarlyListenerSetup()) {
685
664
  const earlyPorts = claimEarlyPorts(handlePort);
686
665
  if (earlyPorts.length > 0) {
687
- this.logger.info(
666
+ this.logger.debug(
688
667
  `\u{1F4E1} Processing ${earlyPorts.length} early port(s) captured during bootstrap`
689
668
  );
690
669
  earlyPorts.forEach(handlePort);
@@ -738,7 +717,7 @@ const _BridgeRuntimeManager = class _BridgeRuntimeManager {
738
717
  });
739
718
  chrome.alarms.onAlarm.addListener(this.handleKeepAliveAlarm);
740
719
  this.keepAliveAlarmRegistered = true;
741
- this.logger.info("Registered keep-alive alarm for background wakeups");
720
+ this.logger.debug("Registered keep-alive alarm for background wakeups");
742
721
  }
743
722
  recordKeepAlivePing(source) {
744
723
  const timestamp = Date.now();
@@ -815,7 +794,7 @@ const _BridgeRuntimeManager = class _BridgeRuntimeManager {
815
794
  void chrome.runtime.lastError;
816
795
  this.diagnostics.lastPortDisconnectError = runtimeErrorMessage;
817
796
  } else {
818
- this.logger.info(`\u{1F4F4} Port disconnected: ${port.name}`);
797
+ this.logger.debug(`\u{1F4F4} Port disconnected: ${port.name}`);
819
798
  }
820
799
  this.diagnostics.portDisconnects++;
821
800
  this.diagnostics.lastPortDisconnectAt = Date.now();
@@ -1073,7 +1052,7 @@ const _BridgeRuntimeManager = class _BridgeRuntimeManager {
1073
1052
  */
1074
1053
  startKeepAlive() {
1075
1054
  if (this.keepAliveTimer) return;
1076
- this.logger.info("Starting keep-alive timer to keep service worker alive");
1055
+ this.logger.debug("Starting keep-alive timer to keep service worker alive");
1077
1056
  this.keepAliveTimer = setInterval(() => {
1078
1057
  chrome.runtime.getPlatformInfo(() => {
1079
1058
  this.recordKeepAlivePing("interval");
@@ -1093,7 +1072,7 @@ const _BridgeRuntimeManager = class _BridgeRuntimeManager {
1093
1072
  if (this.keepAliveTimer) {
1094
1073
  clearInterval(this.keepAliveTimer);
1095
1074
  this.keepAliveTimer = null;
1096
- this.logger.info("Stopped keep-alive timer");
1075
+ this.logger.debug("Stopped keep-alive timer");
1097
1076
  }
1098
1077
  }
1099
1078
  };
@@ -1149,11 +1128,6 @@ const _AlarmAdapter = class _AlarmAdapter {
1149
1128
  await this.clearStaleAlarms();
1150
1129
  chrome.alarms.onAlarm.addListener(this.handleAlarm);
1151
1130
  this.listenerRegistered = true;
1152
- console.log("[AlarmAdapter] \u2705 Chrome Alarms API available and listener registered");
1153
- } else {
1154
- console.log(
1155
- "[AlarmAdapter] \u26A0\uFE0F Chrome Alarms API not available - will use setTimeout fallback"
1156
- );
1157
1131
  }
1158
1132
  };
1159
1133
  /**
@@ -1166,9 +1140,6 @@ const _AlarmAdapter = class _AlarmAdapter {
1166
1140
  chrome.alarms.getAll((alarms) => {
1167
1141
  const staleAlarms = alarms.filter((a) => a.name.startsWith(_AlarmAdapter.ALARM_PREFIX));
1168
1142
  if (staleAlarms.length > 0) {
1169
- console.log(
1170
- `[AlarmAdapter] \u{1F9F9} Clearing ${staleAlarms.length} stale alarms from previous session`
1171
- );
1172
1143
  let cleared = 0;
1173
1144
  staleAlarms.forEach((alarm) => {
1174
1145
  chrome.alarms.clear(alarm.name, () => {
@@ -1198,7 +1169,6 @@ const _AlarmAdapter = class _AlarmAdapter {
1198
1169
  return;
1199
1170
  }
1200
1171
  const jobId = alarm.name.slice(_AlarmAdapter.ALARM_PREFIX.length);
1201
- console.log(`[AlarmAdapter] \u{1F514} Chrome Alarm fired: ${jobId}`);
1202
1172
  this.callbacks.delete(jobId);
1203
1173
  this.triggerCallback?.(jobId);
1204
1174
  };
@@ -1214,17 +1184,11 @@ const _AlarmAdapter = class _AlarmAdapter {
1214
1184
  chrome.alarms.create(alarmName, {
1215
1185
  when
1216
1186
  });
1217
- console.log(
1218
- `[AlarmAdapter] \u23F0 Chrome Alarm scheduled: ${id} in ${Math.round(delay / 1e3)}s`
1219
- );
1220
1187
  this.callbacks.set(id, () => {
1221
1188
  chrome.alarms.clear(alarmName);
1222
1189
  });
1223
1190
  return null;
1224
1191
  }
1225
- console.log(
1226
- `[AlarmAdapter] \u23F1\uFE0F setTimeout fallback: ${id} in ${Math.round(delay / 1e3)}s (Chrome Alarms: ${this.isChromeAlarmsAvailable() ? "available but delay too short" : "unavailable"})`
1227
- );
1228
1192
  const timeoutId = setTimeout(() => {
1229
1193
  this.callbacks.delete(id);
1230
1194
  this.triggerCallback?.(id);
@@ -2095,11 +2059,32 @@ class Scheduler {
2095
2059
  error: console.error,
2096
2060
  debug: console.debug
2097
2061
  };
2098
- this.logger.info("Scheduler initialized");
2062
+ this.logger.debug("Scheduler initialized");
2099
2063
  this.alarm.onTrigger(this.execute.bind(this));
2100
2064
  this.timeout.onTrigger(this.execute.bind(this));
2101
2065
  this.setupPopupVisibilityListener();
2102
2066
  }
2067
+ /**
2068
+ * When `options.schedulerDebug` is true, log at info so diagnostics show without
2069
+ * enabling global debug. Otherwise logs at debug.
2070
+ */
2071
+ logJobDiagnostics(options, message, context) {
2072
+ const ctx = context;
2073
+ if (options?.schedulerDebug) {
2074
+ this.logger.info(message, ctx);
2075
+ } else {
2076
+ this.logger.debug(message, ctx);
2077
+ }
2078
+ }
2079
+ /** Batch summary visible at info if any involved job has `schedulerDebug`. */
2080
+ logBatchIfAnyJobDebug(jobIds, message) {
2081
+ const anyDebug = jobIds.some((jid) => this.registry.meta(jid)?.schedulerDebug);
2082
+ if (anyDebug) {
2083
+ this.logger.info(message);
2084
+ } else {
2085
+ this.logger.debug(message);
2086
+ }
2087
+ }
2103
2088
  /**
2104
2089
  * Setup listener for popup visibility changes.
2105
2090
  * When popup closes, pause all jobs with requiresPopup.
@@ -2107,9 +2092,9 @@ class Scheduler {
2107
2092
  */
2108
2093
  setupPopupVisibilityListener() {
2109
2094
  const visibilityService = PopupVisibilityService.instance;
2110
- this.logger.info("[Scheduler] Setting up popup visibility listener");
2095
+ this.logger.debug("[Scheduler] Setting up popup visibility listener");
2111
2096
  this.popupVisibilityUnsubscribe = visibilityService.onVisibilityChange((isVisible) => {
2112
- this.logger.info(`[Scheduler] Visibility changed: ${isVisible ? "visible" : "hidden"}`);
2097
+ this.logger.debug(`[Scheduler] Visibility changed: ${isVisible ? "visible" : "hidden"}`);
2113
2098
  if (isVisible) {
2114
2099
  this.resumePopupDependentJobs();
2115
2100
  } else {
@@ -2122,13 +2107,14 @@ class Scheduler {
2122
2107
  */
2123
2108
  pausePopupDependentJobs() {
2124
2109
  const jobs = this.registry.listAll();
2125
- this.logger.info(`[Scheduler] pausePopupDependentJobs called, total jobs: ${jobs.length}`);
2110
+ this.logger.debug(`[Scheduler] pausePopupDependentJobs called, total jobs: ${jobs.length}`);
2126
2111
  let pausedCount = 0;
2127
2112
  const pausedJobIds = [];
2128
2113
  for (const job of jobs) {
2129
2114
  const hasRequiresPopup = job.options?.requiresPopup;
2130
2115
  const isPaused = this.registry.getContext(job.id)?.isPaused();
2131
- this.logger.debug(
2116
+ this.logJobDiagnostics(
2117
+ job.options,
2132
2118
  `[Scheduler] Job ${job.id}: requiresPopup=${hasRequiresPopup}, isPaused=${isPaused}`
2133
2119
  );
2134
2120
  if (hasRequiresPopup && !isPaused) {
@@ -2140,11 +2126,12 @@ class Scheduler {
2140
2126
  }
2141
2127
  }
2142
2128
  if (pausedCount > 0) {
2143
- this.logger.info(
2129
+ this.logBatchIfAnyJobDebug(
2130
+ pausedJobIds,
2144
2131
  `[Scheduler] Paused ${pausedCount} popup-dependent jobs (popup closed): ${pausedJobIds.join(", ")}`
2145
2132
  );
2146
2133
  } else {
2147
- this.logger.info(`[Scheduler] No popup-dependent jobs to pause`);
2134
+ this.logger.debug(`[Scheduler] No popup-dependent jobs to pause`);
2148
2135
  }
2149
2136
  }
2150
2137
  /**
@@ -2152,13 +2139,14 @@ class Scheduler {
2152
2139
  */
2153
2140
  resumePopupDependentJobs() {
2154
2141
  const jobs = this.registry.listAll();
2155
- this.logger.info(`[Scheduler] resumePopupDependentJobs called, total jobs: ${jobs.length}`);
2142
+ this.logger.debug(`[Scheduler] resumePopupDependentJobs called, total jobs: ${jobs.length}`);
2156
2143
  let resumedCount = 0;
2157
2144
  const resumedJobIds = [];
2158
2145
  for (const job of jobs) {
2159
2146
  const hasRequiresPopup = job.options?.requiresPopup;
2160
2147
  const isPaused = this.registry.getContext(job.id)?.isPaused();
2161
- this.logger.debug(
2148
+ this.logJobDiagnostics(
2149
+ job.options,
2162
2150
  `[Scheduler] Job ${job.id}: requiresPopup=${hasRequiresPopup}, isPaused=${isPaused}`
2163
2151
  );
2164
2152
  if (hasRequiresPopup && isPaused) {
@@ -2169,11 +2157,12 @@ class Scheduler {
2169
2157
  }
2170
2158
  }
2171
2159
  if (resumedCount > 0) {
2172
- this.logger.info(
2160
+ this.logBatchIfAnyJobDebug(
2161
+ resumedJobIds,
2173
2162
  `[Scheduler] Resumed ${resumedCount} popup-dependent jobs (popup opened): ${resumedJobIds.join(", ")}`
2174
2163
  );
2175
2164
  } else {
2176
- this.logger.info(`[Scheduler] No popup-dependent jobs to resume`);
2165
+ this.logger.debug(`[Scheduler] No popup-dependent jobs to resume`);
2177
2166
  }
2178
2167
  }
2179
2168
  schedule(id, options) {
@@ -2184,7 +2173,8 @@ class Scheduler {
2184
2173
  if (options?.requiresPopup) {
2185
2174
  const isPopupVisible = PopupVisibilityService.instance.isPopupVisible();
2186
2175
  if (!isPopupVisible) {
2187
- this.logger.debug(
2176
+ this.logJobDiagnostics(
2177
+ options,
2188
2178
  `Job ${id} requires popup but popup is not visible, pausing instead of scheduling`
2189
2179
  );
2190
2180
  if (!context.isPaused()) {
@@ -2223,26 +2213,27 @@ class Scheduler {
2223
2213
  if (adapter === this.timeout && timerId) {
2224
2214
  this.registry.setTimeoutId(id, timerId);
2225
2215
  }
2226
- this.logger.info(
2216
+ this.logJobDiagnostics(
2217
+ options,
2227
2218
  `[Scheduler] Job "${id}" scheduled for ${new Date(when).toISOString()} (in ${Math.round(delayMs / 1e3)}s) \u2192 ${adapter === this.alarm ? "\u23F0 AlarmAdapter" : "\u23F1\uFE0F TimeoutAdapter"}`
2228
2219
  );
2229
2220
  }
2230
2221
  pause(id) {
2231
- this.logger.info(`Pausing job ${id}`);
2222
+ this.logJobDiagnostics(this.registry.meta(id), `Pausing job ${id}`);
2232
2223
  this.alarm.cancel(id);
2233
2224
  this.timeout.cancel(id);
2234
2225
  this.registry.pause(id);
2235
2226
  }
2236
2227
  resume(id) {
2237
- this.logger.info(`Resuming job ${id}`);
2238
- this.registry.resume(id);
2239
2228
  const options = this.registry.meta(id);
2229
+ this.logJobDiagnostics(options, `Resuming job ${id}`);
2230
+ this.registry.resume(id);
2240
2231
  if (options) {
2241
2232
  this.schedule(id, options);
2242
2233
  }
2243
2234
  }
2244
2235
  stop(id) {
2245
- this.logger.info(`Stopping job ${id}`);
2236
+ this.logJobDiagnostics(this.registry.meta(id), `Stopping job ${id}`);
2246
2237
  this.alarm.cancel(id);
2247
2238
  this.timeout.cancel(id);
2248
2239
  this.registry.stop(id);
@@ -2252,26 +2243,25 @@ class Scheduler {
2252
2243
  const context = this.registry.getContext(id);
2253
2244
  const options = this.registry.meta(id);
2254
2245
  if (!job || !context) {
2255
- this.logger.debug(`Job ${id} not found or no context`);
2246
+ this.logJobDiagnostics(options, `Job ${id} not found or no context`);
2256
2247
  return;
2257
2248
  }
2258
2249
  if (context.isPaused() || context.isStopped()) {
2259
- this.logger.debug(`Job ${id} is paused or stopped, skipping execution`);
2250
+ this.logJobDiagnostics(options, `Job ${id} is paused or stopped, skipping execution`);
2260
2251
  return;
2261
2252
  }
2262
2253
  if (options?.requiresPopup) {
2263
2254
  const isPopupVisible = PopupVisibilityService.instance.isPopupVisible();
2264
2255
  if (!isPopupVisible) {
2265
- this.logger.debug(`Job ${id} requires popup but popup closed, pausing job`);
2256
+ this.logJobDiagnostics(options, `Job ${id} requires popup but popup closed, pausing job`);
2266
2257
  this.registry.pause(id);
2267
2258
  return;
2268
2259
  }
2269
2260
  }
2270
2261
  try {
2271
2262
  this.registry.updateState(id, JobState.RUNNING);
2272
- this.logger.info(`Executing job ${id}`);
2263
+ this.logJobDiagnostics(options, `Executing job ${id}`);
2273
2264
  const jobInstance = container.get(id);
2274
- this.logger.debug("Job instance:", { jobInstance });
2275
2265
  await jobInstance.handle.bind(jobInstance).call(jobInstance, context);
2276
2266
  if (!context.isStopped() && !context.isPaused()) {
2277
2267
  this.registry.updateState(id, JobState.COMPLETED);
@@ -2284,7 +2274,7 @@ class Scheduler {
2284
2274
  this.logger.error(`Job ${id} execution failed:`, error);
2285
2275
  context.fail(error);
2286
2276
  if (options?.cron || options?.recurring) {
2287
- this.logger.info(`Rescheduling failed recurring job ${id}`);
2277
+ this.logJobDiagnostics(options, `Rescheduling failed recurring job ${id}`);
2288
2278
  this.registry.updateState(id, JobState.SCHEDULED);
2289
2279
  this.schedule(id, options);
2290
2280
  }
@@ -2312,7 +2302,7 @@ class Scheduler {
2312
2302
  * Gracefully shutdown the scheduler, clearing all timers
2313
2303
  */
2314
2304
  shutdown() {
2315
- this.logger.info("Shutting down scheduler...");
2305
+ this.logger.debug("Shutting down scheduler...");
2316
2306
  if (this.popupVisibilityUnsubscribe) {
2317
2307
  this.popupVisibilityUnsubscribe();
2318
2308
  this.popupVisibilityUnsubscribe = void 0;
@@ -2320,7 +2310,7 @@ class Scheduler {
2320
2310
  this.alarm.clear();
2321
2311
  this.timeout.clear();
2322
2312
  this.registry.clear();
2323
- this.logger.info("Scheduler shutdown complete");
2313
+ this.logger.debug("Scheduler shutdown complete");
2324
2314
  }
2325
2315
  /**
2326
2316
  * Get scheduler stats for monitoring
@@ -2941,4 +2931,4 @@ class BootstrapBuilder {
2941
2931
  }
2942
2932
 
2943
2933
  export { AppEventBus as A, EventBusToken as E, JobRegistry as J, NonceService as N, PopupVisibilityService as P, Subscribe as S, SUBSCRIBE_METADATA_KEY as a, getNonceService as b, getPopupVisibilityService as c, claimEarlyPorts as d, arePortsClaimed as e, container as f, getSubscribeMetadata as g, create as h, isEarlyListenerSetup as i, bootstrap as j, Scheduler as k, JobState as l, setupEarlyListener as s };
2944
- //# sourceMappingURL=boot-DPtu_qKj.js.map
2934
+ //# sourceMappingURL=boot-Ap8sFDzW.js.map