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