@dimina-kit/devtools 0.4.0-dev.20260718143821 → 0.4.0-dev.20260728065133

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 (68) hide show
  1. package/dist/main/app/app.js +67 -1
  2. package/dist/main/app/lifecycle.js +9 -0
  3. package/dist/main/index.bundle.js +928 -162
  4. package/dist/main/ipc/bridge-router.d.ts +36 -0
  5. package/dist/main/ipc/bridge-router.js +56 -0
  6. package/dist/main/ipc/index.d.ts +1 -0
  7. package/dist/main/ipc/index.js +1 -0
  8. package/dist/main/ipc/internal-devtools.d.ts +15 -0
  9. package/dist/main/ipc/internal-devtools.js +9 -0
  10. package/dist/main/services/compile-standby.js +4 -0
  11. package/dist/main/services/console-forward/cdp-inject.d.ts +18 -0
  12. package/dist/main/services/console-forward/cdp-inject.js +30 -0
  13. package/dist/main/services/console-forward/global-console-mirror.d.ts +33 -0
  14. package/dist/main/services/console-forward/global-console-mirror.js +71 -0
  15. package/dist/main/services/console-forward/global-diagnostics-mirror.d.ts +33 -0
  16. package/dist/main/services/console-forward/global-diagnostics-mirror.js +73 -0
  17. package/dist/main/services/console-forward/index.d.ts +15 -1
  18. package/dist/main/services/console-forward/index.js +42 -2
  19. package/dist/main/services/console-forward/internal-log.d.ts +11 -0
  20. package/dist/main/services/console-forward/internal-log.js +23 -0
  21. package/dist/main/services/console-forward/open-gated-relay.d.ts +67 -0
  22. package/dist/main/services/console-forward/open-gated-relay.js +55 -0
  23. package/dist/main/services/diagnostics/index.d.ts +10 -0
  24. package/dist/main/services/elements-forward/index.js +14 -96
  25. package/dist/main/services/network-forward/frontend-dispatch.d.ts +64 -0
  26. package/dist/main/services/network-forward/frontend-dispatch.js +113 -8
  27. package/dist/main/services/network-forward/global-body-gate.d.ts +46 -0
  28. package/dist/main/services/network-forward/global-body-gate.js +93 -0
  29. package/dist/main/services/network-forward/global-mirror-test-fixtures.d.ts +48 -0
  30. package/dist/main/services/network-forward/global-mirror-test-fixtures.js +96 -0
  31. package/dist/main/services/network-forward/index.d.ts +31 -0
  32. package/dist/main/services/network-forward/index.js +256 -8
  33. package/dist/main/services/network-forward/user-facing.d.ts +21 -0
  34. package/dist/main/services/network-forward/user-facing.js +50 -0
  35. package/dist/main/services/views/console-filter.d.ts +145 -0
  36. package/dist/main/services/views/console-filter.js +233 -0
  37. package/dist/main/services/views/frontend-bootstrap-gate.d.ts +59 -0
  38. package/dist/main/services/views/frontend-bootstrap-gate.js +117 -0
  39. package/dist/main/services/views/native-simulator-devtools-host.js +138 -30
  40. package/dist/main/services/views/view-manager-devtools-host-test-fixtures.d.ts +76 -0
  41. package/dist/main/services/views/view-manager-devtools-host-test-fixtures.js +182 -0
  42. package/dist/main/services/workbench-context.d.ts +10 -0
  43. package/dist/main/utils/theme.d.ts +10 -6
  44. package/dist/main/utils/theme.js +10 -6
  45. package/dist/main/windows/internal-devtools-window/index.d.ts +66 -0
  46. package/dist/main/windows/internal-devtools-window/index.js +160 -0
  47. package/dist/native-host/render/render.js +89 -73
  48. package/dist/native-host/service/service.js +2 -2
  49. package/dist/preload/windows/host-toolbar-runtime.cjs.map +1 -1
  50. package/dist/preload/windows/simulator.cjs.map +1 -1
  51. package/dist/renderer/assets/index-M5NDq_vi.js +49 -0
  52. package/dist/renderer/assets/{input-c2OcrrZy.js → input-dsgeTmVX.js} +2 -2
  53. package/dist/renderer/assets/ipc-transport-BgFdT9bT.js +9 -0
  54. package/dist/renderer/assets/{popover-kv2qspWz.js → popover-Disfu1cx.js} +2 -2
  55. package/dist/renderer/assets/{select-DKqzMtTh.js → select-DAw1hzkl.js} +2 -2
  56. package/dist/renderer/assets/{settings-dJNKTGr8.js → settings-M_8GFW2M.js} +2 -2
  57. package/dist/renderer/assets/settings-api-DFR5eDl_.js +2 -0
  58. package/dist/renderer/assets/{workbenchSettings-DQ_VP5-W.js → workbenchSettings-CxdXeoOu.js} +2 -2
  59. package/dist/renderer/entries/main/index.html +5 -5
  60. package/dist/renderer/entries/popover/index.html +4 -4
  61. package/dist/renderer/entries/settings/index.html +4 -4
  62. package/dist/renderer/entries/workbench-settings/index.html +3 -3
  63. package/dist/shared/ipc-channels.d.ts +3 -0
  64. package/dist/shared/ipc-channels.js +6 -0
  65. package/package.json +7 -7
  66. package/dist/renderer/assets/index-DfDIvgvK.js +0 -49
  67. package/dist/renderer/assets/ipc-transport-CuDJ07aE.js +0 -9
  68. package/dist/renderer/assets/settings-api-qpXKDRXt.js +0 -2
@@ -545,6 +545,11 @@ var AppChannel = {
545
545
  var AutomationChannel = {
546
546
  GetPort: "automation:port"
547
547
  };
548
+ var InternalDevtoolsChannel = {
549
+ // Open (or focus, if already open) the internal debug DevTools, hosted in
550
+ // its own dedicated window (see internal-devtools-window/index.ts).
551
+ Open: "internal-devtools:open"
552
+ };
548
553
  var SettingsChannel = {
549
554
  SetVisible: "settings:setVisible",
550
555
  ConfigChanged: "settings:configChanged",
@@ -892,7 +897,7 @@ function registerProjectFsIpc(ctx) {
892
897
  }
893
898
 
894
899
  // src/main/app/app.ts
895
- import { app as app15, BrowserWindow as BrowserWindow8, nativeImage, session as session4 } from "electron";
900
+ import { app as app15, BrowserWindow as BrowserWindow9, nativeImage, session as session4 } from "electron";
896
901
  import fs13 from "fs";
897
902
  import path25 from "path";
898
903
 
@@ -1074,6 +1079,261 @@ function wireMainWindowEvents(win, state = {}) {
1074
1079
  return registry;
1075
1080
  }
1076
1081
 
1082
+ // src/main/windows/internal-devtools-window/index.ts
1083
+ import { BrowserWindow as BrowserWindow3, View as View2, WebContentsView as WebContentsView2 } from "electron";
1084
+ function createInternalDevtoolsWindow(target, opts) {
1085
+ let win = null;
1086
+ let hostView = null;
1087
+ const hostChangedHandlers = /* @__PURE__ */ new Set();
1088
+ let currentHost = null;
1089
+ function notifyHostChanged(hostWc) {
1090
+ if (hostWc === currentHost) return;
1091
+ currentHost = hostWc;
1092
+ for (const handler of [...hostChangedHandlers]) {
1093
+ try {
1094
+ handler(hostWc);
1095
+ } catch (err2) {
1096
+ console.warn("[internal-devtools-window] onHostChanged handler threw, other handlers still ran:", err2 instanceof Error ? err2.message : String(err2));
1097
+ }
1098
+ }
1099
+ }
1100
+ function resizeHostView(hostWindow, view) {
1101
+ try {
1102
+ const [width, height] = hostWindow.getContentSize();
1103
+ view.setBounds({ x: 0, y: 0, width, height });
1104
+ } catch {
1105
+ }
1106
+ }
1107
+ function buildOnce() {
1108
+ if (win) return;
1109
+ const hostWindow = new BrowserWindow3({
1110
+ width: 1e3,
1111
+ height: 700,
1112
+ title: "\u5168\u5C40\u8C03\u8BD5",
1113
+ show: false
1114
+ });
1115
+ win = hostWindow;
1116
+ const view = new WebContentsView2();
1117
+ hostView = view;
1118
+ const container = new View2();
1119
+ container.addChildView(view);
1120
+ hostWindow.contentView = container;
1121
+ resizeHostView(hostWindow, view);
1122
+ hostWindow.on("resize", () => resizeHostView(hostWindow, view));
1123
+ hostWindow.on("close", (event) => {
1124
+ if (opts?.isAppQuitting?.()) return;
1125
+ event.preventDefault();
1126
+ hostWindow.hide();
1127
+ notifyHostChanged(null);
1128
+ });
1129
+ hostWindow.on("closed", () => {
1130
+ if (win !== hostWindow) return;
1131
+ win = null;
1132
+ notifyHostChanged(null);
1133
+ });
1134
+ hostWindow.on("hide", () => notifyHostChanged(null));
1135
+ hostWindow.on("show", () => notifyHostChanged(view.webContents));
1136
+ if (!target.webContents.isDestroyed()) {
1137
+ target.webContents.setDevToolsWebContents(view.webContents);
1138
+ target.webContents.openDevTools({ mode: "detach", activate: false });
1139
+ }
1140
+ }
1141
+ return {
1142
+ open() {
1143
+ buildOnce();
1144
+ if (process.env.NODE_ENV === "test") {
1145
+ win.showInactive();
1146
+ } else {
1147
+ win.show();
1148
+ win.focus();
1149
+ }
1150
+ if (hostView) notifyHostChanged(hostView.webContents);
1151
+ },
1152
+ dispose() {
1153
+ if (!win) return;
1154
+ const hostWindow = win;
1155
+ if (!hostWindow.isDestroyed()) hostWindow.destroy();
1156
+ if (win === hostWindow) {
1157
+ win = null;
1158
+ notifyHostChanged(null);
1159
+ }
1160
+ },
1161
+ onHostChanged(handler) {
1162
+ hostChangedHandlers.add(handler);
1163
+ if (currentHost) {
1164
+ queueMicrotask(() => {
1165
+ if (!hostChangedHandlers.has(handler)) return;
1166
+ if (!currentHost) return;
1167
+ try {
1168
+ handler(currentHost);
1169
+ } catch (err2) {
1170
+ console.warn("[internal-devtools-window] onHostChanged catch-up handler threw:", err2 instanceof Error ? err2.message : String(err2));
1171
+ }
1172
+ });
1173
+ }
1174
+ return () => {
1175
+ hostChangedHandlers.delete(handler);
1176
+ };
1177
+ }
1178
+ };
1179
+ }
1180
+
1181
+ // src/main/services/views/inject-when-ready.ts
1182
+ function isFrontendSettled(wc) {
1183
+ try {
1184
+ if (wc.isDestroyed()) return false;
1185
+ const url = wc.getURL();
1186
+ const mainFrameLoading = typeof wc.isLoadingMainFrame === "function" ? wc.isLoadingMainFrame() : wc.isLoading();
1187
+ return !mainFrameLoading && url !== "" && url !== "about:blank";
1188
+ } catch {
1189
+ return false;
1190
+ }
1191
+ }
1192
+ function createLoadDeferredInjector() {
1193
+ const pending = /* @__PURE__ */ new WeakMap();
1194
+ return function injectWhenReady(wc, kind, run) {
1195
+ if (wc.isDestroyed()) return;
1196
+ if (isFrontendSettled(wc)) {
1197
+ run();
1198
+ return;
1199
+ }
1200
+ let kinds = pending.get(wc);
1201
+ if (!kinds) {
1202
+ kinds = /* @__PURE__ */ new Map();
1203
+ pending.set(wc, kinds);
1204
+ }
1205
+ const alreadyHooked = kinds.has(kind);
1206
+ kinds.set(kind, run);
1207
+ if (alreadyHooked) return;
1208
+ wc.once("did-stop-loading", () => {
1209
+ const runner = kinds.get(kind);
1210
+ kinds.delete(kind);
1211
+ if (!runner || wc.isDestroyed()) return;
1212
+ runner();
1213
+ });
1214
+ };
1215
+ }
1216
+
1217
+ // src/main/services/console-forward/open-gated-relay.ts
1218
+ var DEFAULT_INJECT_TIMEOUT_MS = 1e4;
1219
+ function createOpenGatedRelay(onHostChanged, subscribe, inject, opts) {
1220
+ const injectTimeoutMs = opts?.injectTimeoutMs ?? DEFAULT_INJECT_TIMEOUT_MS;
1221
+ const state = /* @__PURE__ */ new WeakMap();
1222
+ let generationSeq = 0;
1223
+ const inFlightTimers = /* @__PURE__ */ new Set();
1224
+ let live = null;
1225
+ function deliver(entry) {
1226
+ if (state.has(entry)) return;
1227
+ const generation = ++generationSeq;
1228
+ state.set(entry, { phase: "pending", generation });
1229
+ const timer = setTimeout(() => {
1230
+ inFlightTimers.delete(timer);
1231
+ const cur = state.get(entry);
1232
+ if (cur && cur.phase === "pending" && cur.generation === generation) state.delete(entry);
1233
+ }, injectTimeoutMs);
1234
+ timer.unref?.();
1235
+ inFlightTimers.add(timer);
1236
+ const settle = (ok2) => {
1237
+ clearTimeout(timer);
1238
+ inFlightTimers.delete(timer);
1239
+ const cur = state.get(entry);
1240
+ if (!cur || cur.phase !== "pending" || cur.generation !== generation) return;
1241
+ if (ok2) state.set(entry, { phase: "done", generation });
1242
+ else state.delete(entry);
1243
+ };
1244
+ Promise.resolve().then(() => inject(entry)).then((ok2) => settle(ok2 === true), () => settle(false));
1245
+ }
1246
+ const unregister = onHostChanged((host) => {
1247
+ live?.dispose();
1248
+ live = host !== null ? subscribe(deliver, { replay: true }) : null;
1249
+ });
1250
+ return {
1251
+ dispose: () => {
1252
+ for (const timer of inFlightTimers) clearTimeout(timer);
1253
+ inFlightTimers.clear();
1254
+ live?.dispose();
1255
+ live = null;
1256
+ unregister();
1257
+ }
1258
+ };
1259
+ }
1260
+
1261
+ // src/main/services/console-forward/cdp-inject.ts
1262
+ function injectViaCdp(broker, target, script, warnTag) {
1263
+ const lease = broker.acquire(target);
1264
+ if (!lease) return false;
1265
+ return lease.send("Runtime.evaluate", { expression: script }).then(
1266
+ (result) => {
1267
+ if (result?.exceptionDetails) {
1268
+ console.warn(`[${warnTag}] Runtime.evaluate reported an exception, will retry on next reopen`);
1269
+ return false;
1270
+ }
1271
+ return true;
1272
+ },
1273
+ (err2) => {
1274
+ console.warn(`[${warnTag}] injection failed, will retry on next reopen:`, err2 instanceof Error ? err2.message : String(err2));
1275
+ return false;
1276
+ }
1277
+ );
1278
+ }
1279
+
1280
+ // src/main/services/console-forward/global-console-mirror.ts
1281
+ var FORWARDABLE_LEVELS = /* @__PURE__ */ new Set(["log", "warn", "error", "info", "debug"]);
1282
+ function buildMirrorScript(entry) {
1283
+ const method = FORWARDABLE_LEVELS.has(entry.level ?? "") ? entry.level : "log";
1284
+ const tag = entry.source === "render" ? "[render]" : "[service]";
1285
+ const argsJson = JSON.stringify(entry.args ?? []);
1286
+ return `(()=>{try{const a=JSON.parse(${JSON.stringify(argsJson)});console[${JSON.stringify(method)}](${JSON.stringify(tag)},...a)}catch(_){}})()`;
1287
+ }
1288
+ function createGlobalConsoleMirror(forwarder, target, onHostChanged, opts) {
1289
+ function inject(entry) {
1290
+ if (target.isDestroyed()) return false;
1291
+ if (!isFrontendSettled(target)) return false;
1292
+ let script;
1293
+ try {
1294
+ script = buildMirrorScript(entry);
1295
+ } catch {
1296
+ return false;
1297
+ }
1298
+ return injectViaCdp(opts.broker, target, script, "global-console-mirror");
1299
+ }
1300
+ return createOpenGatedRelay(
1301
+ onHostChanged,
1302
+ (sink, opts2) => forwarder.subscribe(sink, opts2),
1303
+ inject
1304
+ );
1305
+ }
1306
+
1307
+ // src/main/services/console-forward/global-diagnostics-mirror.ts
1308
+ var DIAGNOSTIC_CONSOLE_CALL = {
1309
+ error: "console.error",
1310
+ warn: "console.warn",
1311
+ info: "console.info"
1312
+ };
1313
+ function buildMirrorScript2(severity, message) {
1314
+ const call = DIAGNOSTIC_CONSOLE_CALL[severity];
1315
+ const argsJson = JSON.stringify([`[dimina-kit] ${message}`]);
1316
+ return `(()=>{try{const a=JSON.parse(${JSON.stringify(argsJson)});${call}(...a)}catch(_){}})()`;
1317
+ }
1318
+ function createGlobalDiagnosticsMirror(diagnostics, target, onHostChanged, opts) {
1319
+ function inject(d) {
1320
+ if (target.isDestroyed()) return false;
1321
+ if (!isFrontendSettled(target)) return false;
1322
+ let script;
1323
+ try {
1324
+ script = buildMirrorScript2(d.severity, d.message);
1325
+ } catch {
1326
+ return false;
1327
+ }
1328
+ return injectViaCdp(opts.broker, target, script, "global-diagnostics-mirror");
1329
+ }
1330
+ return createOpenGatedRelay(
1331
+ onHostChanged,
1332
+ (sink, opts2) => diagnostics.subscribe(sink, opts2),
1333
+ inject
1334
+ );
1335
+ }
1336
+
1077
1337
  // src/main/app/lifecycle.ts
1078
1338
  import { app as app4, globalShortcut as globalShortcut2 } from "electron";
1079
1339
  var appIsQuitting = false;
@@ -1574,7 +1834,7 @@ function createPlacementReconciler(ctx) {
1574
1834
  }
1575
1835
 
1576
1836
  // src/main/services/views/workbench-view.ts
1577
- import { nativeTheme as nativeTheme3, WebContentsView as WebContentsView2 } from "electron";
1837
+ import { nativeTheme as nativeTheme3, WebContentsView as WebContentsView3 } from "electron";
1578
1838
 
1579
1839
  // src/shared/view-ids.ts
1580
1840
  var VIEW_ID = {
@@ -1631,7 +1891,7 @@ function createWorkbenchView(ctx, reconciler) {
1631
1891
  }
1632
1892
  async function attachWorkbench(url) {
1633
1893
  if (workbenchView) return;
1634
- const view = new WebContentsView2({
1894
+ const view = new WebContentsView3({
1635
1895
  webPreferences: {
1636
1896
  nodeIntegration: false,
1637
1897
  contextIsolation: true,
@@ -1755,7 +2015,7 @@ function createWorkbenchView(ctx, reconciler) {
1755
2015
  }
1756
2016
 
1757
2017
  // src/main/services/views/native-simulator-devtools-host.ts
1758
- import { WebContentsView as WebContentsView3 } from "electron";
2018
+ import { WebContentsView as WebContentsView4, webContents as electronWebContents } from "electron";
1759
2019
 
1760
2020
  // src/shared/open-in-editor-resource-path.ts
1761
2021
  function decodePathname(pathname) {
@@ -2216,40 +2476,146 @@ function buildCustomizeTabsScript(keptIds = DEVTOOLS_KEPT_VIEW_IDS) {
2216
2476
  }catch(_){}})()`;
2217
2477
  }
2218
2478
 
2219
- // src/main/services/views/inject-when-ready.ts
2220
- function isFrontendSettled(wc) {
2221
- try {
2222
- if (wc.isDestroyed()) return false;
2223
- const url = wc.getURL();
2224
- const mainFrameLoading = typeof wc.isLoadingMainFrame === "function" ? wc.isLoadingMainFrame() : wc.isLoading();
2225
- return !mainFrameLoading && url !== "" && url !== "about:blank";
2226
- } catch {
2227
- return false;
2228
- }
2479
+ // src/main/services/views/console-filter.ts
2480
+ var DEFAULT_INTERNAL_LOG_FILTER = "-/^\\[service\\]/";
2481
+ function buildConsoleFilterScript(negativeFilter = DEFAULT_INTERNAL_LOG_FILTER) {
2482
+ const keyJson = JSON.stringify("console.text-filter");
2483
+ const markKeyJson = JSON.stringify("console.text-filter.dimina-default");
2484
+ const valueJsonLiteral = JSON.stringify(JSON.stringify(negativeFilter));
2485
+ return `(function(){try{
2486
+ var IFH = globalThis.InspectorFrontendHost;
2487
+ if (!IFH || typeof IFH.getPreferences !== 'function' || typeof IFH.setPreference !== 'function') return;
2488
+ IFH.getPreferences(function(prefs){
2489
+ try {
2490
+ var KEY = ${keyJson};
2491
+ var MARK_KEY = ${markKeyJson};
2492
+ var VALUE = ${valueJsonLiteral};
2493
+ var existing = prefs ? prefs[KEY] : undefined;
2494
+ var mark = prefs ? prefs[MARK_KEY] : undefined;
2495
+ var isUnset = existing === undefined || existing === null || existing === '' || existing === '""';
2496
+ var isOurStaleDefault = !isUnset && mark !== undefined && mark !== null && existing === mark;
2497
+ if (isUnset || isOurStaleDefault) {
2498
+ IFH.setPreference(KEY, VALUE);
2499
+ IFH.setPreference(MARK_KEY, VALUE);
2500
+ }
2501
+ } catch(_){}
2502
+ });
2503
+ }catch(_){}})()`;
2229
2504
  }
2230
- function createLoadDeferredInjector() {
2231
- const pending = /* @__PURE__ */ new WeakMap();
2232
- return function injectWhenReady(wc, kind, run) {
2233
- if (wc.isDestroyed()) return;
2234
- if (isFrontendSettled(wc)) {
2235
- run();
2236
- return;
2237
- }
2238
- let kinds = pending.get(wc);
2239
- if (!kinds) {
2240
- kinds = /* @__PURE__ */ new Map();
2241
- pending.set(wc, kinds);
2505
+ var LIVE_FILTER_POLL_MAX_ATTEMPTS = 100;
2506
+ var LIVE_FILTER_POLL_INTERVAL_MS = 100;
2507
+ function buildLiveConsoleFilterScript(negativeFilter = DEFAULT_INTERNAL_LOG_FILTER) {
2508
+ const filterJson = JSON.stringify(negativeFilter);
2509
+ const maxAttempts = JSON.stringify(LIVE_FILTER_POLL_MAX_ATTEMPTS);
2510
+ const intervalMs = JSON.stringify(LIVE_FILTER_POLL_INTERVAL_MS);
2511
+ return `(function(){
2512
+ var VALUE = ${filterJson};
2513
+ var attempts = 0;
2514
+ function bootstrapReady() {
2515
+ try {
2516
+ var eui = globalThis.EUI;
2517
+ if (!eui || !eui.ShortcutRegistry || !eui.ShortcutRegistry.ShortcutRegistry) return false;
2518
+ eui.ShortcutRegistry.ShortcutRegistry.instance();
2519
+ return true;
2520
+ } catch (_) { return false; }
2521
+ }
2522
+ function tryApply() {
2523
+ attempts++;
2524
+ var scheduleRetry = attempts < ${maxAttempts};
2525
+ // In-realm bootstrap probe FIRST (defense in depth on top of the
2526
+ // main-process whenFrontendBootstrapped gate): touching
2527
+ // Console.ConsoleView.instance() before the front-end's own
2528
+ // MainImpl bootstrap completes constructs IssuesManager early and
2529
+ // permanently kills that bootstrap (ensureFirst conflict) \u2014 the probe
2530
+ // throws BEFORE constructing anything, so a not-ready tick costs
2531
+ // nothing and never touches ConsoleView.
2532
+ if (!bootstrapReady()) {
2533
+ if (scheduleRetry) { setTimeout(tryApply, ${intervalMs}); return; }
2534
+ console.warn('[console-filter] gave up applying the live Console filter after ' + attempts + ' attempts \u2014 the front-end bootstrap never completed');
2535
+ return;
2536
+ }
2537
+ try {
2538
+ var ConsoleNS = globalThis.Console;
2539
+ var view = ConsoleNS && ConsoleNS.ConsoleView ? ConsoleNS.ConsoleView.instance() : null;
2540
+ var f = view ? view.filter : null;
2541
+ if (!f || !f.textFilterUI || typeof f.textFilterUI.setValue !== 'function' || typeof f.textFilterUI.value !== 'function') {
2542
+ if (scheduleRetry) { setTimeout(tryApply, ${intervalMs}); return; }
2543
+ console.warn('[console-filter] gave up applying the live Console filter after ' + attempts + ' attempts \u2014 Console.ConsoleView never became usable');
2544
+ return;
2545
+ }
2546
+ var current = f.textFilterUI.value();
2547
+ var isUnset = current === undefined || current === null || current === '';
2548
+ var isOurDefault = current === VALUE;
2549
+ if (isUnset || isOurDefault) {
2550
+ f.textFilterUI.setValue(VALUE);
2551
+ if (typeof f.updateCurrentFilter === 'function') f.updateCurrentFilter();
2552
+ if (typeof f.onFilterChanged === 'function') f.onFilterChanged();
2553
+ }
2554
+ // Either applied, or a real user customization was detected \u2014 both
2555
+ // are terminal: nothing left for a later retry to accomplish.
2556
+ } catch(_) {
2557
+ if (scheduleRetry) setTimeout(tryApply, ${intervalMs});
2558
+ }
2242
2559
  }
2243
- const alreadyHooked = kinds.has(kind);
2244
- kinds.set(kind, run);
2245
- if (alreadyHooked) return;
2246
- wc.once("did-stop-loading", () => {
2247
- const runner = kinds.get(kind);
2248
- kinds.delete(kind);
2249
- if (!runner || wc.isDestroyed()) return;
2250
- runner();
2251
- });
2252
- };
2560
+ tryApply();
2561
+ })()`;
2562
+ }
2563
+
2564
+ // src/main/services/views/frontend-bootstrap-gate.ts
2565
+ var FRONTEND_BOOTSTRAP_PROBE_SCRIPT = `(() => {
2566
+ try {
2567
+ const eui = globalThis.EUI
2568
+ if (!eui || !eui.ShortcutRegistry || !eui.ShortcutRegistry.ShortcutRegistry) return false
2569
+ eui.ShortcutRegistry.ShortcutRegistry.instance()
2570
+ return true
2571
+ } catch (_) {
2572
+ return false
2573
+ }
2574
+ })()`;
2575
+ var DEFAULT_TIMEOUT_MS = 45e3;
2576
+ var DEFAULT_INTERVAL_MS = 150;
2577
+ function whenFrontendBootstrapped(wc, opts) {
2578
+ const timeoutMs = opts?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
2579
+ const intervalMs = opts?.intervalMs ?? DEFAULT_INTERVAL_MS;
2580
+ return new Promise((resolve) => {
2581
+ let timer = null;
2582
+ let settled = false;
2583
+ const finish = (ready) => {
2584
+ if (settled) return;
2585
+ settled = true;
2586
+ clearTimeout(deadline);
2587
+ if (timer) {
2588
+ clearTimeout(timer);
2589
+ timer = null;
2590
+ }
2591
+ resolve(ready);
2592
+ };
2593
+ const deadline = setTimeout(() => {
2594
+ console.warn(`[frontend-bootstrap-gate] front-end bootstrap probe never reported ready within ${timeoutMs}ms \u2014 bootstrap-gated injections stay skipped for this host`);
2595
+ finish(false);
2596
+ }, timeoutMs);
2597
+ deadline.unref?.();
2598
+ const attempt = () => {
2599
+ if (wc.isDestroyed()) {
2600
+ finish(false);
2601
+ return;
2602
+ }
2603
+ Promise.resolve().then(() => wc.executeJavaScript(FRONTEND_BOOTSTRAP_PROBE_SCRIPT)).then((ready) => ready === true, () => false).then((ready) => {
2604
+ if (settled) return;
2605
+ if (wc.isDestroyed()) {
2606
+ finish(false);
2607
+ return;
2608
+ }
2609
+ if (ready) {
2610
+ finish(true);
2611
+ return;
2612
+ }
2613
+ timer = setTimeout(attempt, intervalMs);
2614
+ timer.unref?.();
2615
+ });
2616
+ };
2617
+ attempt();
2618
+ });
2253
2619
  }
2254
2620
 
2255
2621
  // src/main/services/network-forward/index.ts
@@ -2408,6 +2774,165 @@ function buildChunkedDispatchScript(chunks, totalSize) {
2408
2774
  const arr = JSON.stringify(chunks);
2409
2775
  return `(()=>{try{if(!(window.DevToolsAPI&&typeof window.DevToolsAPI.dispatchMessageChunk==='function'))return false;const cs=JSON.parse(${JSON.stringify(arr)});for(let i=0;i<cs.length;i++){try{if(i===0){window.DevToolsAPI.dispatchMessageChunk(cs[i], ${totalSize})}else{window.DevToolsAPI.dispatchMessageChunk(cs[i])}}catch(_){}}return true;}catch(_){return false}})()`;
2410
2776
  }
2777
+ function buildSingleDispatchScript(message) {
2778
+ return `(()=>{try{if(!${PROBE_DEVTOOLS_API})return false;window.DevToolsAPI.dispatchMessage(JSON.parse(${JSON.stringify(message)}));return true;}catch(_){return false}})()`;
2779
+ }
2780
+ function createFrontendReplyChannel(hostWc, isDisposed) {
2781
+ function dispatchToFrontend(message) {
2782
+ if (isDisposed() || hostWc.isDestroyed()) return;
2783
+ if (!isFrontendSettled(hostWc)) return;
2784
+ let json;
2785
+ try {
2786
+ json = JSON.stringify(message);
2787
+ } catch {
2788
+ return;
2789
+ }
2790
+ if (json.length > MAX_SINGLE_DISPATCH_CHARS) {
2791
+ const chunks = [];
2792
+ for (let i = 0; i < json.length; i += CHUNK_CHARS) chunks.push(json.slice(i, i + CHUNK_CHARS));
2793
+ let script2;
2794
+ try {
2795
+ script2 = buildChunkedDispatchScript(chunks, json.length);
2796
+ } catch {
2797
+ return;
2798
+ }
2799
+ hostWc.executeJavaScript(script2, true).catch(() => {
2800
+ });
2801
+ return;
2802
+ }
2803
+ let script;
2804
+ try {
2805
+ script = buildSingleDispatchScript(json);
2806
+ } catch {
2807
+ return;
2808
+ }
2809
+ hostWc.executeJavaScript(script, true).catch(() => {
2810
+ });
2811
+ }
2812
+ function replyResult(cmd, result) {
2813
+ const msg = { id: cmd.id, result };
2814
+ if (cmd.sessionId) msg.sessionId = cmd.sessionId;
2815
+ dispatchToFrontend(msg);
2816
+ }
2817
+ function replyError(cmd, message) {
2818
+ const msg = { id: cmd.id, error: { code: -32e3, message } };
2819
+ if (cmd.sessionId) msg.sessionId = cmd.sessionId;
2820
+ dispatchToFrontend(msg);
2821
+ }
2822
+ return { dispatchToFrontend, replyResult, replyError };
2823
+ }
2824
+ function drainOutboundBatch(batch, handle) {
2825
+ if (!Array.isArray(batch)) return;
2826
+ for (const raw of batch) {
2827
+ if (!raw || typeof raw !== "object") continue;
2828
+ const cmd = raw;
2829
+ if (typeof cmd.method !== "string") continue;
2830
+ handle(cmd);
2831
+ }
2832
+ }
2833
+ function answerNetworkBodyCommand(cmd, provider, reply) {
2834
+ const requestId = cmd.params?.requestId;
2835
+ if (!provider || typeof requestId !== "string") {
2836
+ reply.replyError(cmd, "No resource with given identifier found");
2837
+ return;
2838
+ }
2839
+ const lookup = cmd.method === "Network.getRequestPostData" ? provider.getRequestPostData(requestId) : provider.getResponseBody(requestId);
2840
+ lookup.then(
2841
+ (result) => reply.replyResult(cmd, result),
2842
+ (err2) => reply.replyError(cmd, err2 instanceof Error ? err2.message : String(err2))
2843
+ );
2844
+ }
2845
+
2846
+ // src/main/services/network-forward/user-facing.ts
2847
+ var USER_FACING_SCHEMES = /* @__PURE__ */ new Set(["http:", "https:", "ws:", "wss:"]);
2848
+ function isUserFacingRequest(url, internalOrigins) {
2849
+ let parsed;
2850
+ try {
2851
+ parsed = new URL(url);
2852
+ } catch {
2853
+ return true;
2854
+ }
2855
+ if (!USER_FACING_SCHEMES.has(parsed.protocol)) return false;
2856
+ for (const baseUrl of internalOrigins ?? []) {
2857
+ if (!baseUrl) continue;
2858
+ try {
2859
+ if (parsed.origin === new URL(baseUrl).origin) return false;
2860
+ } catch {
2861
+ }
2862
+ }
2863
+ return true;
2864
+ }
2865
+
2866
+ // src/main/services/network-forward/global-body-gate.ts
2867
+ var NETWORK_BODY_METHODS = ["Network.getResponseBody", "Network.getRequestPostData"];
2868
+ var DRAIN_INTERVAL_MS = 150;
2869
+ function buildNetworkOnlyHookScript() {
2870
+ const netMethods = JSON.stringify(NETWORK_BODY_METHODS);
2871
+ const vprefix = JSON.stringify(VIRTUAL_REQUEST_ID_PREFIX);
2872
+ return `(function(){try{
2873
+ if (globalThis.__diminaGlobalNetworkHookInstalled) return 'already';
2874
+ var OUT = (globalThis.__diminaGlobalNetworkOutbound = globalThis.__diminaGlobalNetworkOutbound || []);
2875
+ var NET_METHODS = ${netMethods};
2876
+ var VPREFIX = ${vprefix};
2877
+ function isNetworkBody(m){
2878
+ if (!m || !m.method) return false;
2879
+ if (NET_METHODS.indexOf(m.method) < 0) return false;
2880
+ return !!(m.params && typeof m.params.requestId === 'string' && m.params.requestId.indexOf(VPREFIX) === 0);
2881
+ }
2882
+ var IFH = globalThis.InspectorFrontendHost;
2883
+ if (IFH && typeof IFH.sendMessageToBackend === 'function' && !IFH.__diminaGlobalNetworkWrapped){
2884
+ var origSend = IFH.sendMessageToBackend.bind(IFH);
2885
+ IFH.sendMessageToBackend = function(message){
2886
+ try {
2887
+ var m = (typeof message === 'string') ? JSON.parse(message) : message;
2888
+ if (isNetworkBody(m)){
2889
+ OUT.push({ id: (m && typeof m.id === 'number') ? m.id : null,
2890
+ method: m.method, params: m.params || {},
2891
+ sessionId: (m && m.sessionId) ? m.sessionId : null });
2892
+ return;
2893
+ }
2894
+ } catch(_){ /* fall through to original on any parse hiccup */ }
2895
+ return origSend(message);
2896
+ };
2897
+ IFH.__diminaGlobalNetworkWrapped = true;
2898
+ globalThis.__diminaGlobalNetworkHookInstalled = true;
2899
+ return 'installed';
2900
+ }
2901
+ return 'partial';
2902
+ }catch(e){ return 'error:' + (e && e.message); }})()`;
2903
+ }
2904
+ function buildReconcileScript() {
2905
+ return `(function(){var status; try { status = ${buildNetworkOnlyHookScript()}; } catch(e){ status = 'error:'+(e&&e.message); }var batch = []; try { if (globalThis.__diminaGlobalNetworkOutbound) batch = globalThis.__diminaGlobalNetworkOutbound.splice(0); } catch(_){}return { status: status, batch: batch };})()`;
2906
+ }
2907
+ function installGlobalNetworkBodyGate(hostWc, bodies) {
2908
+ let disposed = false;
2909
+ let reconcileTimer = null;
2910
+ const reply = createFrontendReplyChannel(hostWc, () => disposed);
2911
+ function handleOutbound(batch) {
2912
+ drainOutboundBatch(batch, (cmd) => answerNetworkBodyCommand(cmd, bodies, reply));
2913
+ }
2914
+ reconcileTimer = setInterval(() => {
2915
+ if (disposed || hostWc.isDestroyed()) {
2916
+ stop();
2917
+ return;
2918
+ }
2919
+ if (!isFrontendSettled(hostWc)) return;
2920
+ hostWc.executeJavaScript(buildReconcileScript()).then((res) => {
2921
+ if (disposed) return;
2922
+ const r = res ?? {};
2923
+ handleOutbound(r.batch);
2924
+ }).catch(() => {
2925
+ });
2926
+ }, DRAIN_INTERVAL_MS);
2927
+ function stop() {
2928
+ disposed = true;
2929
+ if (reconcileTimer) {
2930
+ clearInterval(reconcileTimer);
2931
+ reconcileTimer = null;
2932
+ }
2933
+ }
2934
+ return stop;
2935
+ }
2411
2936
 
2412
2937
  // src/main/services/network-forward/index.ts
2413
2938
  var VIRTUAL_REQUEST_ID_PREFIX = "dimina:sim:";
@@ -2566,6 +3091,122 @@ function createNetworkForwarder(bridge) {
2566
3091
  const broker = bridge.broker ?? createCdpSessionBroker({ connections: bridge.connections });
2567
3092
  let devtoolsWc = null;
2568
3093
  let devtoolsHostDisposable = null;
3094
+ let globalDevtoolsWc = null;
3095
+ let globalDevtoolsHostDisposable = null;
3096
+ let globalBodyGateStop = null;
3097
+ const MAX_GLOBAL_PENDING_QUEUE = 2e3;
3098
+ let globalPendingQueue = [];
3099
+ let globalPendingOverflowWarned = false;
3100
+ let globalFlushTimer = null;
3101
+ const GLOBAL_FLUSH_POLL_MAX_MS = 6e4;
3102
+ function clearGlobalPending() {
3103
+ globalPendingQueue = [];
3104
+ globalPendingOverflowWarned = false;
3105
+ if (globalFlushTimer) {
3106
+ clearTimeout(globalFlushTimer);
3107
+ globalFlushTimer = null;
3108
+ }
3109
+ }
3110
+ function scheduleGlobalFlush(startedAt = Date.now()) {
3111
+ if (globalFlushTimer) return;
3112
+ if (Date.now() - startedAt >= GLOBAL_FLUSH_POLL_MAX_MS) return;
3113
+ globalFlushTimer = setTimeout(() => {
3114
+ globalFlushTimer = null;
3115
+ if (globalPendingQueue.length === 0) return;
3116
+ if (!globalDevtoolsWc || globalDevtoolsWc.isDestroyed()) {
3117
+ clearGlobalPending();
3118
+ return;
3119
+ }
3120
+ if (!isFrontendSettled(globalDevtoolsWc)) {
3121
+ scheduleGlobalFlush(startedAt);
3122
+ return;
3123
+ }
3124
+ flushGlobalPending();
3125
+ }, READY_RETRY_MS);
3126
+ globalFlushTimer.unref?.();
3127
+ }
3128
+ function flushGlobalPending() {
3129
+ if (globalPendingQueue.length === 0) return;
3130
+ const target = globalDevtoolsWc;
3131
+ if (!target || target.isDestroyed()) {
3132
+ clearGlobalPending();
3133
+ return;
3134
+ }
3135
+ while (globalPendingQueue.length > 0) {
3136
+ const { batch, chunked, remaining } = packDispatchBatch(globalPendingQueue, MAX_SINGLE_DISPATCH_CHARS, MAX_BATCH_CHARS);
3137
+ globalPendingQueue = remaining;
3138
+ for (const msg of chunked) dispatchChunked(target, msg);
3139
+ if (batch.length > 0) {
3140
+ target.executeJavaScript(buildDispatchScript(batch), true).catch(() => {
3141
+ });
3142
+ }
3143
+ }
3144
+ globalPendingOverflowWarned = false;
3145
+ }
3146
+ function enqueueGlobalPending(json) {
3147
+ if (globalPendingQueue.length >= MAX_GLOBAL_PENDING_QUEUE) {
3148
+ globalPendingQueue.shift();
3149
+ if (!globalPendingOverflowWarned) {
3150
+ globalPendingOverflowWarned = true;
3151
+ console.warn(`[network-forward] global mirror queue overflow (cap ${MAX_GLOBAL_PENDING_QUEUE}): dropping oldest events while the debug window front-end is still loading`);
3152
+ }
3153
+ }
3154
+ globalPendingQueue.push(json);
3155
+ scheduleGlobalFlush();
3156
+ }
3157
+ function applyGlobalDevtoolsHost(host) {
3158
+ globalDevtoolsHostDisposable?.dispose();
3159
+ globalDevtoolsHostDisposable = null;
3160
+ globalBodyGateStop?.();
3161
+ globalBodyGateStop = null;
3162
+ clearGlobalPending();
3163
+ globalDevtoolsWc = host && !host.isDestroyed() ? host : null;
3164
+ if (!globalDevtoolsWc) return;
3165
+ const target = globalDevtoolsWc;
3166
+ const onHostDestroyed = () => {
3167
+ if (globalDevtoolsWc === target) globalDevtoolsWc = null;
3168
+ globalBodyGateStop?.();
3169
+ globalBodyGateStop = null;
3170
+ clearGlobalPending();
3171
+ };
3172
+ const reg = bridge.connections;
3173
+ if (reg && typeof target.once === "function") {
3174
+ const owned = reg.acquire(target).own(onHostDestroyed);
3175
+ globalDevtoolsHostDisposable = toDisposable3(() => owned.dispose());
3176
+ } else {
3177
+ if (typeof target.once === "function") target.once("destroyed", onHostDestroyed);
3178
+ globalDevtoolsHostDisposable = toDisposable3(() => {
3179
+ try {
3180
+ target.removeListener?.("destroyed", onHostDestroyed);
3181
+ } catch {
3182
+ }
3183
+ });
3184
+ }
3185
+ globalBodyGateStop = installGlobalNetworkBodyGate(target, {
3186
+ getResponseBody: (requestId) => bodyCache.lookup(requestId),
3187
+ getRequestPostData: (requestId) => postDataCache.lookup(requestId)
3188
+ });
3189
+ }
3190
+ function dispatchToGlobal(method, params) {
3191
+ if (!globalDevtoolsWc || globalDevtoolsWc.isDestroyed()) return;
3192
+ let json;
3193
+ try {
3194
+ json = JSON.stringify({ method, params });
3195
+ } catch {
3196
+ return;
3197
+ }
3198
+ if (!isFrontendSettled(globalDevtoolsWc)) {
3199
+ enqueueGlobalPending(json);
3200
+ return;
3201
+ }
3202
+ flushGlobalPending();
3203
+ if (json.length > MAX_SINGLE_DISPATCH_CHARS) {
3204
+ dispatchChunked(globalDevtoolsWc, json);
3205
+ return;
3206
+ }
3207
+ globalDevtoolsWc.executeJavaScript(buildDispatchScript([json]), true).catch(() => {
3208
+ });
3209
+ }
2569
3210
  let sink = "idle";
2570
3211
  let probeConsoleBuffer = [];
2571
3212
  let readyTimeoutTimer = null;
@@ -2775,10 +3416,12 @@ function createNetworkForwarder(bridge) {
2775
3416
  function wireNetworkCapture(wc, source, attach, epoch) {
2776
3417
  const ns = new RequestIdNamespace(epoch);
2777
3418
  const pending = /* @__PURE__ */ new Map();
3419
+ const userFacingByRawId = /* @__PURE__ */ new Map();
2778
3420
  const postDataWanted = /* @__PURE__ */ new Set();
2779
3421
  const prefetchBodies = (rawId, encodedDataLength) => {
2780
- if (sink === "degraded") return;
2781
- if (sink === "idle" && !resolveDevtoolsWc()) return;
3422
+ const userSinkUsable = sink !== "degraded" && !(sink === "idle" && !resolveDevtoolsWc());
3423
+ const globalUsable = globalDevtoolsWc !== null && !globalDevtoolsWc.isDestroyed();
3424
+ if (!userSinkUsable && !globalUsable) return;
2782
3425
  const virtualId = ns.resolve(rawId);
2783
3426
  const knownOversized = typeof encodedDataLength === "number" && encodedDataLength > DEFAULT_PER_ENTRY_MAX_CHARS;
2784
3427
  if (!knownOversized) {
@@ -2812,20 +3455,25 @@ function createNetworkForwarder(bridge) {
2812
3455
  const req = pending.get(p.requestId);
2813
3456
  if (req) req.status = p.response?.status ?? 0;
2814
3457
  }
3458
+ function retirePending(rawId) {
3459
+ userFacingByRawId.delete(rawId);
3460
+ const req = pending.get(rawId);
3461
+ if (!req) return void 0;
3462
+ pending.delete(rawId);
3463
+ return req;
3464
+ }
2815
3465
  function onLoadingFinished(params) {
2816
3466
  const p = params;
2817
3467
  if (typeof p?.requestId === "string") prefetchBodies(p.requestId, p.encodedDataLength);
2818
- const req = pending.get(p.requestId);
3468
+ const req = retirePending(p?.requestId);
2819
3469
  if (!req) return;
2820
- pending.delete(p.requestId);
2821
3470
  maybeFallback({ source, url: req.url, method: req.method, status: req.status });
2822
3471
  }
2823
3472
  function onLoadingFailed(params) {
2824
3473
  const p = params;
2825
3474
  postDataWanted.delete(p?.requestId);
2826
- const req = pending.get(p.requestId);
3475
+ const req = retirePending(p?.requestId);
2827
3476
  if (!req) return;
2828
- pending.delete(p.requestId);
2829
3477
  maybeFallback({
2830
3478
  source,
2831
3479
  url: req.url,
@@ -2840,10 +3488,29 @@ function createNetworkForwarder(bridge) {
2840
3488
  "Network.loadingFinished": onLoadingFinished,
2841
3489
  "Network.loadingFailed": onLoadingFailed
2842
3490
  };
3491
+ function resolveUserFacing(method, params, rawId) {
3492
+ if (method === "Network.requestWillBeSent") {
3493
+ const url = params?.request?.url;
3494
+ const verdict = typeof url === "string" ? isUserFacingRequest(url, [bridge.getResourceServerBaseUrl?.(), bridge.getSimulatorServerBaseUrl?.()]) : true;
3495
+ if (rawId) {
3496
+ if (userFacingByRawId.size >= MAX_PENDING) userFacingByRawId.clear();
3497
+ userFacingByRawId.set(rawId, verdict);
3498
+ }
3499
+ return verdict;
3500
+ }
3501
+ if (rawId && userFacingByRawId.has(rawId)) return userFacingByRawId.get(rawId);
3502
+ if (method === "Network.requestWillBeSentExtraInfo") return false;
3503
+ return true;
3504
+ }
2843
3505
  const onMessage = (_event, method, params) => {
2844
3506
  if (FORWARDED_METHODS.has(method)) {
2845
3507
  const rewritten = rewriteRequestId(method, params, ns);
2846
- enqueueNative(rewritten.method, rewritten.params);
3508
+ dispatchToGlobal(rewritten.method, rewritten.params);
3509
+ const rawId = params?.requestId;
3510
+ const userFacing = resolveUserFacing(method, params, typeof rawId === "string" ? rawId : void 0);
3511
+ if (userFacing) {
3512
+ enqueueNative(rewritten.method, rewritten.params);
3513
+ }
2847
3514
  } else if (REWRITE_REQUEST_ID_METHODS.has(method)) {
2848
3515
  rewriteRequestId(method, params, ns);
2849
3516
  }
@@ -3004,6 +3671,14 @@ function createNetworkForwarder(bridge) {
3004
3671
  readyRetryTimer = null;
3005
3672
  }
3006
3673
  });
3674
+ registry.add(() => {
3675
+ globalDevtoolsHostDisposable?.dispose();
3676
+ globalDevtoolsHostDisposable = null;
3677
+ globalBodyGateStop?.();
3678
+ globalBodyGateStop = null;
3679
+ globalDevtoolsWc = null;
3680
+ clearGlobalPending();
3681
+ });
3007
3682
  registry.add(() => {
3008
3683
  bodyCache.clear();
3009
3684
  postDataCache.clear();
@@ -3020,6 +3695,7 @@ function createNetworkForwarder(bridge) {
3020
3695
  detachSimulator,
3021
3696
  attachRenderGuest,
3022
3697
  setDevtoolsHost: (wc) => applyDevtoolsHost(wc),
3698
+ setGlobalDevtoolsHost: (wc) => applyGlobalDevtoolsHost(wc),
3023
3699
  // report() has no observing debugger, so there's no live CDP event to push
3024
3700
  // natively — surface it via the console fallback line.
3025
3701
  report: (record) => forwardToConsole(record),
@@ -3048,13 +3724,13 @@ function routeByDomain(method) {
3048
3724
  function isRenderEventMethod(method) {
3049
3725
  return routeByDomain(method) === "render";
3050
3726
  }
3051
- var NETWORK_BODY_METHODS = [
3727
+ var NETWORK_BODY_METHODS2 = [
3052
3728
  "Network.getResponseBody",
3053
3729
  "Network.getRequestPostData"
3054
3730
  ];
3055
3731
  function buildElementsHookScript() {
3056
3732
  const prefixes = JSON.stringify(RENDER_DOMAIN_PREFIXES);
3057
- const netMethods = JSON.stringify(NETWORK_BODY_METHODS);
3733
+ const netMethods = JSON.stringify(NETWORK_BODY_METHODS2);
3058
3734
  const vprefix = JSON.stringify(VIRTUAL_REQUEST_ID_PREFIX);
3059
3735
  return `(function(){try{
3060
3736
  if (globalThis.__diminaElementsHookInstalled) return 'already';
@@ -3102,17 +3778,14 @@ function buildElementsHookScript() {
3102
3778
  return 'partial';
3103
3779
  }catch(e){ return 'error:' + (e && e.message); }})()`;
3104
3780
  }
3105
- function buildReconcileScript() {
3781
+ function buildReconcileScript2() {
3106
3782
  return `(function(){var status; try { status = ${buildElementsHookScript()}; } catch(e){ status = 'error:'+(e&&e.message); }var batch = []; try { if (globalThis.__diminaElementsOutbound) batch = globalThis.__diminaElementsOutbound.splice(0); } catch(_){}return { status: status, batch: batch };})()`;
3107
3783
  }
3108
- function buildDispatchScript2(message) {
3109
- return `(()=>{try{if(!${PROBE_DEVTOOLS_API})return false;window.DevToolsAPI.dispatchMessage(JSON.parse(${JSON.stringify(message)}));return true;}catch(_){return false}})()`;
3110
- }
3111
3784
  function buildDocumentUpdatedScript() {
3112
3785
  const msg = JSON.stringify({ method: "DOM.documentUpdated", params: {} });
3113
- return buildDispatchScript2(msg);
3786
+ return buildSingleDispatchScript(msg);
3114
3787
  }
3115
- var DRAIN_INTERVAL_MS = 150;
3788
+ var DRAIN_INTERVAL_MS2 = 150;
3116
3789
  function installElementsForward(deps) {
3117
3790
  const { devtoolsWc, bridge } = deps;
3118
3791
  const ownsBroker = !deps.broker;
@@ -3148,39 +3821,7 @@ function installElementsForward(deps) {
3148
3821
  }
3149
3822
  }
3150
3823
  };
3151
- function dispatchToFrontend(message) {
3152
- if (disposed || devtoolsWc.isDestroyed()) return;
3153
- if (!isFrontendSettled(devtoolsWc)) return;
3154
- let json;
3155
- try {
3156
- json = JSON.stringify(message);
3157
- } catch {
3158
- return;
3159
- }
3160
- if (json.length > MAX_SINGLE_DISPATCH_CHARS) {
3161
- const chunks = [];
3162
- for (let i = 0; i < json.length; i += CHUNK_CHARS) {
3163
- chunks.push(json.slice(i, i + CHUNK_CHARS));
3164
- }
3165
- let script2;
3166
- try {
3167
- script2 = buildChunkedDispatchScript(chunks, json.length);
3168
- } catch {
3169
- return;
3170
- }
3171
- devtoolsWc.executeJavaScript(script2, true).catch(() => {
3172
- });
3173
- return;
3174
- }
3175
- let script;
3176
- try {
3177
- script = buildDispatchScript2(json);
3178
- } catch {
3179
- return;
3180
- }
3181
- devtoolsWc.executeJavaScript(script, true).catch(() => {
3182
- });
3183
- }
3824
+ const { dispatchToFrontend, replyResult, replyError } = createFrontendReplyChannel(devtoolsWc, () => disposed);
3184
3825
  function pushDocumentUpdated() {
3185
3826
  if (disposed || devtoolsWc.isDestroyed()) return;
3186
3827
  if (!isFrontendSettled(devtoolsWc)) return;
@@ -3193,16 +3834,6 @@ function installElementsForward(deps) {
3193
3834
  devtoolsWc.executeJavaScript(script, true).catch(() => {
3194
3835
  });
3195
3836
  }
3196
- function replyResult(cmd, result) {
3197
- const msg = { id: cmd.id, result };
3198
- if (cmd.sessionId) msg.sessionId = cmd.sessionId;
3199
- dispatchToFrontend(msg);
3200
- }
3201
- function replyError(cmd, message) {
3202
- const msg = { id: cmd.id, error: { code: -32e3, message } };
3203
- if (cmd.sessionId) msg.sessionId = cmd.sessionId;
3204
- dispatchToFrontend(msg);
3205
- }
3206
3837
  function activeRenderWc() {
3207
3838
  try {
3208
3839
  const wc = bridge.getActiveRenderWc(deps.appId);
@@ -3275,34 +3906,16 @@ function installElementsForward(deps) {
3275
3906
  });
3276
3907
  }
3277
3908
  function answerNetworkCommand(cmd) {
3278
- const provider = deps.network;
3279
- const requestId = cmd.params?.requestId;
3280
- if (!provider || typeof requestId !== "string") {
3281
- replyError(cmd, "No resource with given identifier found");
3282
- return;
3283
- }
3284
- const lookup = cmd.method === "Network.getRequestPostData" ? provider.getRequestPostData(requestId) : provider.getResponseBody(requestId);
3285
- lookup.then(
3286
- (result) => {
3287
- if (!disposed) replyResult(cmd, result);
3288
- },
3289
- (err2) => {
3290
- if (!disposed) replyError(cmd, err2 instanceof Error ? err2.message : String(err2));
3291
- }
3292
- );
3909
+ answerNetworkBodyCommand(cmd, deps.network, { replyResult, replyError });
3293
3910
  }
3294
3911
  function handleOutbound(batch) {
3295
- if (!Array.isArray(batch)) return;
3296
- for (const raw of batch) {
3297
- if (!raw || typeof raw !== "object") continue;
3298
- const cmd = raw;
3299
- if (typeof cmd.method !== "string") continue;
3912
+ drainOutboundBatch(batch, (cmd) => {
3300
3913
  if (cmd.route === "network") {
3301
3914
  answerNetworkCommand(cmd);
3302
- continue;
3915
+ return;
3303
3916
  }
3304
3917
  routeCommand(cmd);
3305
- }
3918
+ });
3306
3919
  }
3307
3920
  const onRenderEvent = (event) => {
3308
3921
  if (disposed) return;
@@ -3325,7 +3938,7 @@ function installElementsForward(deps) {
3325
3938
  return;
3326
3939
  }
3327
3940
  if (!isFrontendSettled(devtoolsWc)) return;
3328
- devtoolsWc.executeJavaScript(buildReconcileScript()).then((res) => {
3941
+ devtoolsWc.executeJavaScript(buildReconcileScript2()).then((res) => {
3329
3942
  if (disposed) return;
3330
3943
  const r = res ?? {};
3331
3944
  if (r.status === "installed") {
@@ -3336,7 +3949,7 @@ function installElementsForward(deps) {
3336
3949
  handleOutbound(r.batch);
3337
3950
  }).catch(() => {
3338
3951
  });
3339
- }, DRAIN_INTERVAL_MS);
3952
+ }, DRAIN_INTERVAL_MS2);
3340
3953
  };
3341
3954
  devtoolsWc.on("dom-ready", onReady);
3342
3955
  onReady();
@@ -3556,6 +4169,7 @@ function createDevtoolsHost(ctx, reconciler, deps) {
3556
4169
  let nativeDevtoolsSourceWc = null;
3557
4170
  let devtoolsHostUsed = false;
3558
4171
  let unsubscribeNativeRenderEvents = null;
4172
+ let unsubscribeNativeServiceHostReady = null;
3559
4173
  let stopElementsForward = null;
3560
4174
  let stopServiceConsole = null;
3561
4175
  let nativeDevtoolsRetryTimer = null;
@@ -3594,6 +4208,13 @@ function createDevtoolsHost(ctx, reconciler, deps) {
3594
4208
  }
3595
4209
  unsubscribeNativeRenderEvents = null;
3596
4210
  }
4211
+ if (unsubscribeNativeServiceHostReady) {
4212
+ try {
4213
+ unsubscribeNativeServiceHostReady();
4214
+ } catch {
4215
+ }
4216
+ unsubscribeNativeServiceHostReady = null;
4217
+ }
3597
4218
  closeNativeDevtoolsSource();
3598
4219
  }
3599
4220
  function injectOpenResourceHandler(serviceWc, devtoolsWc) {
@@ -3624,6 +4245,25 @@ function createDevtoolsHost(ctx, reconciler, deps) {
3624
4245
  } catch {
3625
4246
  }
3626
4247
  }
4248
+ function applyConsoleFilter(devtoolsWc) {
4249
+ try {
4250
+ if (devtoolsWc.isDestroyed()) return;
4251
+ const inject = () => {
4252
+ void whenFrontendBootstrapped(devtoolsWc).then((ready) => {
4253
+ if (!ready || devtoolsWc.isDestroyed()) return;
4254
+ try {
4255
+ void devtoolsWc.executeJavaScript(buildConsoleFilterScript()).catch(() => {
4256
+ });
4257
+ void devtoolsWc.executeJavaScript(buildLiveConsoleFilterScript()).catch(() => {
4258
+ });
4259
+ } catch {
4260
+ }
4261
+ });
4262
+ };
4263
+ injectWhenReady(devtoolsWc, "console-filter", inject);
4264
+ } catch {
4265
+ }
4266
+ }
3627
4267
  function wireOpenInEditor(serviceWc, devtoolsWc) {
3628
4268
  if (!devtoolsWc.isDestroyed()) {
3629
4269
  injectWhenReady(devtoolsWc, "open-in-editor", () => injectOpenResourceHandler(serviceWc, devtoolsWc));
@@ -3669,6 +4309,7 @@ function createDevtoolsHost(ctx, reconciler, deps) {
3669
4309
  devtoolsHostUsed = true;
3670
4310
  wireOpenInEditor(next, simulatorView.webContents);
3671
4311
  customizeDevtoolsTabs(simulatorView.webContents);
4312
+ applyConsoleFilter(simulatorView.webContents);
3672
4313
  try {
3673
4314
  stopServiceConsole?.();
3674
4315
  } catch {
@@ -3694,8 +4335,10 @@ function createDevtoolsHost(ctx, reconciler, deps) {
3694
4335
  if (!wc || wc.isDestroyed()) return false;
3695
4336
  return pointNativeDevtoolsAtServiceWc(wc);
3696
4337
  }
3697
- function scheduleNativeDevtoolsFollow(appId, attempt = 0) {
3698
- if (attempt >= 20) return;
4338
+ const NATIVE_DEVTOOLS_FALLBACK_POLL_MAX_MS = 6e4;
4339
+ const NATIVE_DEVTOOLS_FALLBACK_POLL_INTERVAL_MS = 50;
4340
+ function scheduleNativeDevtoolsFollow(appId, startedAt = Date.now()) {
4341
+ if (Date.now() - startedAt >= NATIVE_DEVTOOLS_FALLBACK_POLL_MAX_MS) return;
3699
4342
  if (!ctx.bridge?.isNativeHost()) return;
3700
4343
  const token = nativeDevtoolsRetryToken;
3701
4344
  if (nativeDevtoolsRetryTimer) clearTimeout(nativeDevtoolsRetryTimer);
@@ -3703,14 +4346,27 @@ function createDevtoolsHost(ctx, reconciler, deps) {
3703
4346
  nativeDevtoolsRetryTimer = null;
3704
4347
  if (token !== nativeDevtoolsRetryToken) return;
3705
4348
  if (pointNativeDevtoolsAtActiveServiceHost(appId)) return;
3706
- scheduleNativeDevtoolsFollow(appId, attempt + 1);
3707
- }, 50);
4349
+ scheduleNativeDevtoolsFollow(appId, startedAt);
4350
+ }, NATIVE_DEVTOOLS_FALLBACK_POLL_INTERVAL_MS);
3708
4351
  }
3709
4352
  function followNativeDevtoolsServiceHost(appId) {
3710
4353
  clearNativeDevtoolsRetry();
3711
4354
  if (pointNativeDevtoolsAtActiveServiceHost(appId)) return;
3712
4355
  scheduleNativeDevtoolsFollow(appId);
3713
4356
  }
4357
+ function onNativeServiceHostReady(event) {
4358
+ if (!ctx.bridge?.isNativeHost()) return;
4359
+ if (!simulatorView || simulatorView.webContents.isDestroyed()) return;
4360
+ const wc = electronWebContents.fromId(event.serviceWcId);
4361
+ if (!wc || wc.isDestroyed()) return;
4362
+ const current = ctx.bridge.getServiceWc(event.appId);
4363
+ if (current && current.id !== event.serviceWcId) return;
4364
+ if (pointNativeDevtoolsAtServiceWc(wc)) {
4365
+ clearNativeDevtoolsRetry();
4366
+ return;
4367
+ }
4368
+ scheduleNativeDevtoolsFollow(event.appId);
4369
+ }
3714
4370
  function onNativeRenderEvent(event) {
3715
4371
  if (event.kind !== "activePage" && event.kind !== "domReady") return;
3716
4372
  followNativeDevtoolsServiceHost(event.appId);
@@ -3726,7 +4382,7 @@ function createDevtoolsHost(ctx, reconciler, deps) {
3726
4382
  }
3727
4383
  simulatorView = null;
3728
4384
  }
3729
- simulatorView = new WebContentsView3();
4385
+ simulatorView = new WebContentsView4();
3730
4386
  const devtoolsWc = simulatorView.webContents;
3731
4387
  raiseExecuteJavaScriptListenerCeiling(devtoolsWc);
3732
4388
  ctx.networkForward?.setDevtoolsHost(devtoolsWc);
@@ -3757,27 +4413,21 @@ function createDevtoolsHost(ctx, reconciler, deps) {
3757
4413
  });
3758
4414
  }
3759
4415
  injectWhenReady(devtoolsWc, "console-default", () => {
3760
- devtoolsWc.executeJavaScript(`
3761
- (function() {
3762
- try { localStorage.setItem('panel-selectedTab', '"console"') } catch {}
3763
- let tries = 0
3764
- const timer = setInterval(() => {
3765
- tries++
4416
+ void whenFrontendBootstrapped(devtoolsWc).then((ready) => {
4417
+ if (!ready || devtoolsWc.isDestroyed()) return;
4418
+ devtoolsWc.executeJavaScript(`
4419
+ (function() {
3766
4420
  try {
3767
- const UI = globalThis.UI
3768
- const vm = UI && UI.ViewManager && typeof UI.ViewManager.instance === 'function'
3769
- ? UI.ViewManager.instance()
4421
+ var EUI = globalThis.EUI
4422
+ var vm = EUI && EUI.ViewManager && EUI.ViewManager.ViewManager
4423
+ && typeof EUI.ViewManager.ViewManager.instance === 'function'
4424
+ ? EUI.ViewManager.ViewManager.instance()
3770
4425
  : null
3771
- if (vm && typeof vm.showView === 'function') {
3772
- vm.showView('console')
3773
- clearInterval(timer)
3774
- return
3775
- }
3776
- } catch {}
3777
- if (tries > 80) clearInterval(timer)
3778
- }, 50)
3779
- })()
3780
- `).catch(() => {
4426
+ if (vm && typeof vm.showView === 'function') void vm.showView('console')
4427
+ } catch (_) {}
4428
+ })()
4429
+ `).catch(() => {
4430
+ });
3781
4431
  });
3782
4432
  });
3783
4433
  reconciler.reconcileNow();
@@ -3788,6 +4438,7 @@ function createDevtoolsHost(ctx, reconciler, deps) {
3788
4438
  rebuildDevtoolsHostView();
3789
4439
  if (ctx.bridge?.isNativeHost()) {
3790
4440
  unsubscribeNativeRenderEvents = ctx.bridge.onRenderEvent(onNativeRenderEvent);
4441
+ unsubscribeNativeServiceHostReady = ctx.bridge.onServiceHostReady(onNativeServiceHostReady);
3791
4442
  followNativeDevtoolsServiceHost();
3792
4443
  }
3793
4444
  }
@@ -3829,7 +4480,7 @@ function createDevtoolsHost(ctx, reconciler, deps) {
3829
4480
  }
3830
4481
 
3831
4482
  // src/main/services/views/host-toolbar-view.ts
3832
- import { WebContentsView as WebContentsView4 } from "electron";
4483
+ import { WebContentsView as WebContentsView5 } from "electron";
3833
4484
 
3834
4485
  // src/main/services/views/host-toolbar-session-runtime.ts
3835
4486
  import { session } from "electron";
@@ -4025,7 +4676,7 @@ function createHostToolbarView(ctx, reconciler, deps) {
4025
4676
  if (hostToolbarPreloadOverride !== null) {
4026
4677
  webPreferences.preload = hostToolbarPreloadOverride;
4027
4678
  }
4028
- const view = new WebContentsView4({ webPreferences });
4679
+ const view = new WebContentsView5({ webPreferences });
4029
4680
  hostToolbarView = view;
4030
4681
  hostToolbarPort.attach(view.webContents);
4031
4682
  try {
@@ -4127,7 +4778,7 @@ function createHostToolbarView(ctx, reconciler, deps) {
4127
4778
  }
4128
4779
 
4129
4780
  // src/main/services/views/overlay-panels-view.ts
4130
- import { WebContentsView as WebContentsView5 } from "electron";
4781
+ import { WebContentsView as WebContentsView6 } from "electron";
4131
4782
  import path8 from "path";
4132
4783
 
4133
4784
  // src/main/services/layout/index.ts
@@ -4195,7 +4846,7 @@ function createOverlayPanelsView(ctx, reconciler, deps) {
4195
4846
  }
4196
4847
  async function showSettings() {
4197
4848
  if (!settingsView) {
4198
- settingsView = new WebContentsView5({
4849
+ settingsView = new WebContentsView6({
4199
4850
  webPreferences: {
4200
4851
  nodeIntegration: false,
4201
4852
  contextIsolation: true,
@@ -4217,7 +4868,7 @@ function createOverlayPanelsView(ctx, reconciler, deps) {
4217
4868
  }
4218
4869
  function showPopover(data) {
4219
4870
  hidePopover();
4220
- const popover = new WebContentsView5({
4871
+ const popover = new WebContentsView6({
4221
4872
  webPreferences: {
4222
4873
  nodeIntegration: false,
4223
4874
  contextIsolation: true,
@@ -4284,7 +4935,7 @@ function createOverlayPanelsView(ctx, reconciler, deps) {
4284
4935
  }
4285
4936
 
4286
4937
  // src/main/services/views/native-simulator-view.ts
4287
- import { ipcMain as ipcMain2, nativeTheme as nativeTheme4, shell as shell2, WebContentsView as WebContentsView6, webContents as webContents2 } from "electron";
4938
+ import { ipcMain as ipcMain2, nativeTheme as nativeTheme4, shell as shell2, WebContentsView as WebContentsView7, webContents as webContents2 } from "electron";
4288
4939
 
4289
4940
  // src/main/services/simulator/custom-apis.ts
4290
4941
  async function handleCustomApiBridgeRequest(apis, req) {
@@ -4613,7 +5264,7 @@ function createNativeSimulatorView(ctx, reconciler, deps) {
4613
5264
  const route = parseRoute(simulatorUrl);
4614
5265
  const partition = miniappPartition(route?.appId, ctx.workspace?.getProjectPath());
4615
5266
  configureMiniappSession(partition);
4616
- const view = new WebContentsView6({
5267
+ const view = new WebContentsView7({
4617
5268
  webPreferences: {
4618
5269
  nodeIntegration: false,
4619
5270
  contextIsolation: false,
@@ -4852,10 +5503,10 @@ function createWindowService(mainWindow) {
4852
5503
  }
4853
5504
 
4854
5505
  // src/main/windows/settings-window/create.ts
4855
- import { BrowserWindow as BrowserWindow3 } from "electron";
5506
+ import { BrowserWindow as BrowserWindow4 } from "electron";
4856
5507
  import path9 from "path";
4857
5508
  async function createSettingsWindow(parent, rendererDir2) {
4858
- const win = new BrowserWindow3({
5509
+ const win = new BrowserWindow4({
4859
5510
  width: 420,
4860
5511
  height: 560,
4861
5512
  minWidth: 380,
@@ -5540,7 +6191,11 @@ function setupCompileWorkerStandby(ctx, deps = {}) {
5540
6191
  ctx.diagnostics?.report({
5541
6192
  severity: EVENT_SEVERITY[ev.type] ?? "info",
5542
6193
  code: "compile-standby",
5543
- message: detail
6194
+ message: detail,
6195
+ // Devtools-tooling-only state, unrelated to the inspected mini-program
6196
+ // — must never reach the right-panel (user-facing) Console panel; see
6197
+ // console-forward/index.ts's audience gate and global-diagnostics-mirror.ts.
6198
+ audience: "internal"
5544
6199
  });
5545
6200
  } catch {
5546
6201
  }
@@ -6139,6 +6794,13 @@ var settingsModule = {
6139
6794
  setup: (ctx) => registerSettingsIpc(ctx)
6140
6795
  };
6141
6796
 
6797
+ // src/main/ipc/internal-devtools.ts
6798
+ function registerInternalDevtoolsIpc(ctx) {
6799
+ return new IpcRegistry(ctx.senderPolicy).handle(InternalDevtoolsChannel.Open, () => {
6800
+ ctx.internalDevtoolsWindow?.open();
6801
+ });
6802
+ }
6803
+
6142
6804
  // src/main/ipc/simulator-module.ts
6143
6805
  import { DisposableRegistry as DisposableRegistry5 } from "@dimina-kit/electron-deck/main";
6144
6806
 
@@ -6297,7 +6959,7 @@ function setCorsHeaders(res) {
6297
6959
  }
6298
6960
 
6299
6961
  // src/main/windows/service-host-window/create.ts
6300
- import { app as app10, BrowserWindow as BrowserWindow4 } from "electron";
6962
+ import { app as app10, BrowserWindow as BrowserWindow5 } from "electron";
6301
6963
  import path16 from "node:path";
6302
6964
  import { pathToFileURL as pathToFileURL2 } from "node:url";
6303
6965
  var SERVICE_HOST_PARTITION = SHARED_MINIAPP_PARTITION;
@@ -6306,7 +6968,7 @@ var serviceHostHtmlPath = path16.join(devtoolsPackageRoot, "dist/service-host/se
6306
6968
  function constructServiceHostWindow(opts = {}) {
6307
6969
  const partition = opts.partition ?? SERVICE_HOST_PARTITION;
6308
6970
  configureMiniappSession(partition);
6309
- return new BrowserWindow4({
6971
+ return new BrowserWindow5({
6310
6972
  width: 980,
6311
6973
  height: 720,
6312
6974
  show: false,
@@ -6387,7 +7049,7 @@ function createServiceHostWindow(opts) {
6387
7049
  }
6388
7050
 
6389
7051
  // src/main/services/service-host-pool/pool.ts
6390
- import { BrowserWindow as BrowserWindow5 } from "electron";
7052
+ import { BrowserWindow as BrowserWindow6 } from "electron";
6391
7053
  var BLANK_URL = "about:blank";
6392
7054
  var HARD_MAX_POOL_SIZE = 4;
6393
7055
  var RESET_STORAGES = [
@@ -6584,7 +7246,7 @@ var ServiceHostPool = class {
6584
7246
  }
6585
7247
  }
6586
7248
  createWindow(spec) {
6587
- return new BrowserWindow5({
7249
+ return new BrowserWindow6({
6588
7250
  show: false,
6589
7251
  width: spec.size?.width,
6590
7252
  height: spec.size?.height,
@@ -6692,20 +7354,32 @@ var ServiceHostPool = class {
6692
7354
 
6693
7355
  // src/main/services/console-forward/index.ts
6694
7356
  import { DisposableRegistry as DisposableRegistry3, toDisposable as toDisposable4 } from "@dimina-kit/electron-deck/main";
6695
- var FORWARDABLE_LEVELS = /* @__PURE__ */ new Set(["log", "warn", "error", "info", "debug"]);
7357
+
7358
+ // src/main/services/console-forward/internal-log.ts
7359
+ var SERVICE_PREFIX = "[service]";
7360
+ var RENDER_PREFIX = "[system]";
7361
+ function isInternalLogMessage(entry) {
7362
+ const first = entry.args?.[0];
7363
+ if (typeof first !== "string") return false;
7364
+ if (first === RENDER_PREFIX) return true;
7365
+ return first === SERVICE_PREFIX || first.startsWith(`${SERVICE_PREFIX} `);
7366
+ }
7367
+
7368
+ // src/main/services/console-forward/index.ts
7369
+ var FORWARDABLE_LEVELS2 = /* @__PURE__ */ new Set(["log", "warn", "error", "info", "debug"]);
6696
7370
  function buildForwardScript2(level, args) {
6697
- const method = FORWARDABLE_LEVELS.has(level) ? level : "log";
7371
+ const method = FORWARDABLE_LEVELS2.has(level) ? level : "log";
6698
7372
  const argsJson = JSON.stringify(args ?? []);
6699
7373
  return `(()=>{try{const a=JSON.parse(${JSON.stringify(argsJson)});console[${JSON.stringify(method)}]('[\u89C6\u56FE]',...a)}catch(_){}})()
6700
7374
  //# sourceURL=${RENDER_FORWARD_SOURCE_URL}`;
6701
7375
  }
6702
- var DIAGNOSTIC_CONSOLE_CALL = {
7376
+ var DIAGNOSTIC_CONSOLE_CALL2 = {
6703
7377
  error: "console.error",
6704
7378
  warn: "console.warn",
6705
7379
  info: "console.info"
6706
7380
  };
6707
7381
  function buildDiagnosticScript(severity, message) {
6708
- const call = DIAGNOSTIC_CONSOLE_CALL[severity];
7382
+ const call = DIAGNOSTIC_CONSOLE_CALL2[severity];
6709
7383
  const argsJson = JSON.stringify([`[dimina-kit] ${message}`]);
6710
7384
  return `(()=>{try{const a=JSON.parse(${JSON.stringify(argsJson)});${call}(...a)}catch(_){}})()
6711
7385
  //# sourceURL=${RENDER_FORWARD_SOURCE_URL}`;
@@ -6713,6 +7387,8 @@ function buildDiagnosticScript(severity, message) {
6713
7387
  function createConsoleForwarder(bridge, diagnostics) {
6714
7388
  const sinks = /* @__PURE__ */ new Set();
6715
7389
  const registry = new DisposableRegistry3();
7390
+ const CONSOLE_BUFFER_CAP = 200;
7391
+ const buffer = [];
6716
7392
  const pendingBySession = /* @__PURE__ */ new Map();
6717
7393
  const pendingGlobal = [];
6718
7394
  const readySessions = /* @__PURE__ */ new Set();
@@ -6721,6 +7397,7 @@ function createConsoleForwarder(bridge, diagnostics) {
6721
7397
  });
6722
7398
  }
6723
7399
  function handleDiagnostic(d) {
7400
+ if (d.audience === "internal") return;
6724
7401
  if (d.appSessionId) {
6725
7402
  const wc2 = readySessions.has(d.appSessionId) && bridge.getServiceWcForBridge ? bridge.getServiceWcForBridge(d.appSessionId) : null;
6726
7403
  if (wc2 && !wc2.isDestroyed()) {
@@ -6743,6 +7420,7 @@ function createConsoleForwarder(bridge, diagnostics) {
6743
7420
  registry.add(diagnostics.subscribe(handleDiagnostic, { replay: true }));
6744
7421
  }
6745
7422
  function forwardRenderToServiceHost(entry) {
7423
+ if (isInternalLogMessage(entry)) return;
6746
7424
  let wc = null;
6747
7425
  if (entry.bridgeId && bridge.getServiceWcForBridge) {
6748
7426
  wc = bridge.getServiceWcForBridge(entry.bridgeId);
@@ -6764,6 +7442,8 @@ function createConsoleForwarder(bridge, diagnostics) {
6764
7442
  // (render only — see loop-safety invariant in the module header).
6765
7443
  emit(raw) {
6766
7444
  const entry = raw ?? {};
7445
+ buffer.push(entry);
7446
+ if (buffer.length > CONSOLE_BUFFER_CAP) buffer.shift();
6767
7447
  for (const sink of sinks) {
6768
7448
  try {
6769
7449
  sink(entry);
@@ -6772,7 +7452,15 @@ function createConsoleForwarder(bridge, diagnostics) {
6772
7452
  }
6773
7453
  if (entry.source === "render") forwardRenderToServiceHost(entry);
6774
7454
  },
6775
- subscribe(sink) {
7455
+ subscribe(sink, opts) {
7456
+ if (opts?.replay) {
7457
+ for (const entry of buffer) {
7458
+ try {
7459
+ sink(entry);
7460
+ } catch {
7461
+ }
7462
+ }
7463
+ }
6776
7464
  sinks.add(sink);
6777
7465
  return registry.add(toDisposable4(() => {
6778
7466
  sinks.delete(sink);
@@ -6794,6 +7482,7 @@ function createConsoleForwarder(bridge, diagnostics) {
6794
7482
  },
6795
7483
  dispose() {
6796
7484
  sinks.clear();
7485
+ buffer.length = 0;
6797
7486
  pendingBySession.clear();
6798
7487
  pendingGlobal.length = 0;
6799
7488
  readySessions.clear();
@@ -7467,6 +8156,9 @@ function installBridgeRouter(ctx) {
7467
8156
  pool: null,
7468
8157
  emitRenderEvent: () => {
7469
8158
  },
8159
+ emitServiceHostReady: () => {
8160
+ },
8161
+ lastServiceHostReady: null,
7470
8162
  connections: ctx.connections,
7471
8163
  debugTap: createDebugTap({ enabled: resolveDebugTapEnabled() }),
7472
8164
  appLifecycle: createAppLifecycleController(),
@@ -7514,6 +8206,18 @@ function installBridgeRouter(ctx) {
7514
8206
  }
7515
8207
  };
7516
8208
  state.emitRenderEvent = emitRenderEvent;
8209
+ const serviceHostReadyListeners = /* @__PURE__ */ new Set();
8210
+ const emitServiceHostReady = (event) => {
8211
+ state.lastServiceHostReady = event;
8212
+ for (const listener of serviceHostReadyListeners) {
8213
+ try {
8214
+ listener(event);
8215
+ } catch (error) {
8216
+ console.warn("[bridge-router] service-host-ready listener threw:", error);
8217
+ }
8218
+ }
8219
+ };
8220
+ state.emitServiceHostReady = emitServiceHostReady;
7517
8221
  const bridgeHandle = {
7518
8222
  isNativeHost: () => true,
7519
8223
  resolveRenderWc: (bridgeId) => {
@@ -7539,6 +8243,10 @@ function installBridgeRouter(ctx) {
7539
8243
  const ap = resolveCurrentApp(state, ctx, appId);
7540
8244
  return ap?.pageStack ?? null;
7541
8245
  },
8246
+ getResourceBaseUrl: (appId) => {
8247
+ const ap = resolveCurrentApp(state, ctx, appId);
8248
+ return ap?.resourceBaseUrl ?? null;
8249
+ },
7542
8250
  getActiveRenderWc: (appId) => {
7543
8251
  const ap = resolveCurrentApp(state, ctx, appId);
7544
8252
  if (!ap) return null;
@@ -7549,6 +8257,23 @@ function installBridgeRouter(ctx) {
7549
8257
  renderEventListeners.add(listener);
7550
8258
  return () => renderEventListeners.delete(listener);
7551
8259
  },
8260
+ onServiceHostReady: (listener) => {
8261
+ serviceHostReadyListeners.add(listener);
8262
+ const candidate = state.lastServiceHostReady;
8263
+ if (candidate) {
8264
+ queueMicrotask(() => {
8265
+ if (!serviceHostReadyListeners.has(listener)) return;
8266
+ const ap = state.appSessions.get(candidate.appSessionId);
8267
+ if (!ap || ap.serviceWc.isDestroyed() || ap.serviceWc.id !== candidate.serviceWcId) return;
8268
+ try {
8269
+ listener(candidate);
8270
+ } catch (error) {
8271
+ console.warn("[bridge-router] service-host-ready catch-up listener threw:", error);
8272
+ }
8273
+ });
8274
+ }
8275
+ return () => serviceHostReadyListeners.delete(listener);
8276
+ },
7552
8277
  getDevice: () => currentDevice,
7553
8278
  setDevice: (device) => {
7554
8279
  currentDevice = device;
@@ -8078,6 +8803,7 @@ function handleNavCallback(state, sender, payload) {
8078
8803
  async function bootServiceHost(state, ap, ctx) {
8079
8804
  if (state.appSessions.get(ap.appSessionId) !== ap) return;
8080
8805
  ctx.consoleForwarder?.notifyServiceHostReady?.(ap.appSessionId);
8806
+ state.emitServiceHostReady({ appId: ap.appId, appSessionId: ap.appSessionId, serviceWcId: ap.serviceWc.id });
8081
8807
  ap.logicInjected = await injectLogicBundle(ap);
8082
8808
  if (!ap.logicInjected) {
8083
8809
  const reason = reportLogicLoadFailure(ap, ctx);
@@ -12128,7 +12854,7 @@ function enableDevRendererAutoReload(rendererDir2) {
12128
12854
  const watcher = fs13.watch(rendererDir2, { recursive: true }, () => {
12129
12855
  if (reloadTimer) clearTimeout(reloadTimer);
12130
12856
  reloadTimer = setTimeout(() => {
12131
- for (const win of BrowserWindow8.getAllWindows()) {
12857
+ for (const win of BrowserWindow9.getAllWindows()) {
12132
12858
  win.webContents.reload();
12133
12859
  }
12134
12860
  }, 300);
@@ -12164,10 +12890,33 @@ async function createDevtoolsRuntime(config = {}, onInstanceCreated) {
12164
12890
  context.connections.acquire(mainWindow.webContents);
12165
12891
  context.registry.add(registerAppIpc(context));
12166
12892
  context.registry.add(registerProjectFsIpc(context));
12893
+ context.internalDevtoolsWindow = createInternalDevtoolsWindow(mainWindow, { isAppQuitting });
12894
+ context.registry.add(toDisposable8(() => context.internalDevtoolsWindow?.dispose()));
12895
+ context.registry.add(registerInternalDevtoolsIpc(context));
12167
12896
  context.registry.add(setupSimulatorSessionPolicy());
12168
12897
  context.registry.add(installThemeBackgroundSync());
12169
12898
  if (!config.adapter) context.registry.add(setupCompileWorkerStandby(context));
12170
12899
  registerBuiltinModules(config, context);
12900
+ if (context.consoleForwarder && context.internalDevtoolsWindow) {
12901
+ const consoleMirror = createGlobalConsoleMirror(
12902
+ context.consoleForwarder,
12903
+ mainWindow.webContents,
12904
+ context.internalDevtoolsWindow.onHostChanged,
12905
+ // CDP transport (never executeJavaScript) — see the mirror's inject()
12906
+ // doc for the setDevToolsWebContents + external-CDP double-attach hang.
12907
+ { broker: context.cdpSessionBroker }
12908
+ );
12909
+ context.registry.add(toDisposable8(() => consoleMirror.dispose()));
12910
+ }
12911
+ if (context.diagnostics && context.internalDevtoolsWindow) {
12912
+ const diagnosticsMirror = createGlobalDiagnosticsMirror(
12913
+ context.diagnostics,
12914
+ mainWindow.webContents,
12915
+ context.internalDevtoolsWindow.onHostChanged,
12916
+ { broker: context.cdpSessionBroker }
12917
+ );
12918
+ context.registry.add(toDisposable8(() => diagnosticsMirror.dispose()));
12919
+ }
12171
12920
  const simSession = session4.fromPartition(SHARED_MINIAPP_PARTITION);
12172
12921
  context.registry.add(setupSimulatorTempFiles(simSession));
12173
12922
  installMenu(config, mainWindow, context);
@@ -12267,6 +13016,17 @@ async function createDevtoolsRuntime(config = {}, onInstanceCreated) {
12267
13016
  if (context.bridge?.isNativeHost()) {
12268
13017
  const networkForward = createNetworkForwarder({
12269
13018
  getServiceWc: (appId) => context.bridge?.getServiceWc(appId) ?? null,
13019
+ getResourceServerBaseUrl: () => context.bridge?.getResourceBaseUrl?.() ?? null,
13020
+ // The simulator shell's own static-asset server (serves simulator.html
13021
+ // + its JS/CSS, independent from the resource server above — see
13022
+ // NetworkForwarderBridge.getSimulatorServerBaseUrl's doc). Host is
13023
+ // always 'localhost' — see shared/simulator-route.ts's
13024
+ // buildSimulatorUrlFromSpec default. Absent (null port) when no
13025
+ // project is open.
13026
+ getSimulatorServerBaseUrl: () => {
13027
+ const port = context.workspace?.getSession()?.port;
13028
+ return typeof port === "number" ? `http://localhost:${port}/` : null;
13029
+ },
12270
13030
  connections: context.connections,
12271
13031
  broker: context.cdpSessionBroker
12272
13032
  });
@@ -12275,6 +13035,12 @@ async function createDevtoolsRuntime(config = {}, onInstanceCreated) {
12275
13035
  context.registry.add(() => {
12276
13036
  context.networkForward = void 0;
12277
13037
  });
13038
+ context.registry.add(toDisposable8(
13039
+ context.internalDevtoolsWindow?.onHostChanged((hostWc) => {
13040
+ context.networkForward?.setGlobalDevtoolsHost(hostWc);
13041
+ }) ?? (() => {
13042
+ })
13043
+ ));
12278
13044
  context.registry.add(setupSimulatorWxml(mainWindow.webContents, {
12279
13045
  senderPolicy: context.senderPolicy,
12280
13046
  bridge: context.bridge,