@module-federation/devtools 2.4.0 → 2.5.1
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.
- package/README.md +3 -0
- package/dist/es/App.js +17 -2
- package/dist/es/App_module.css +3 -3
- package/dist/es/component/LoadingTrace/index.js +944 -0
- package/dist/es/component/LoadingTrace/index.module.js +5 -0
- package/dist/es/component/LoadingTrace/index_module.css +876 -0
- package/dist/es/i18n/index.js +178 -0
- package/dist/es/utils/chrome/index.js +3 -4
- package/dist/es/utils/chrome/messages.js +7 -1
- package/dist/es/utils/chrome/observability-plugin.js +93 -0
- package/dist/es/utils/chrome/observability-shared.js +99 -0
- package/dist/es/utils/chrome/observability.js +208 -0
- package/dist/es/utils/chrome/override-remote.js +2 -42
- package/dist/es/utils/chrome/post-message-listener.js +14 -0
- package/dist/es/utils/chrome/snapshot-plugin.js +2 -36
- package/dist/es/utils/data/index.js +5 -25
- package/dist/es/vendor/basic-proxy-core.js +155 -0
- package/dist/es/worker/index.js +27 -8
- package/dist/lib/App.js +17 -2
- package/dist/lib/App_module.css +3 -3
- package/dist/lib/component/LoadingTrace/index.js +954 -0
- package/dist/lib/component/LoadingTrace/index.module.js +25 -0
- package/dist/lib/component/LoadingTrace/index_module.css +876 -0
- package/dist/lib/i18n/index.js +178 -0
- package/dist/lib/utils/chrome/index.js +3 -4
- package/dist/lib/utils/chrome/messages.js +11 -2
- package/dist/lib/utils/chrome/observability-plugin.js +86 -0
- package/dist/lib/utils/chrome/observability-shared.js +126 -0
- package/dist/lib/utils/chrome/observability.js +234 -0
- package/dist/lib/utils/chrome/override-remote.js +5 -52
- package/dist/lib/utils/chrome/post-message-listener.js +11 -0
- package/dist/lib/utils/chrome/snapshot-plugin.js +5 -46
- package/dist/lib/utils/data/index.js +6 -28
- package/dist/lib/vendor/basic-proxy-core.js +147 -0
- package/dist/lib/worker/index.js +27 -8
- package/dist/types/src/component/LoadingTrace/index.d.ts +6 -0
- package/dist/types/src/utils/chrome/messages.d.ts +3 -0
- package/dist/types/src/utils/chrome/observability-plugin.d.ts +1 -0
- package/dist/types/src/utils/chrome/observability-shared.d.ts +41 -0
- package/dist/types/src/utils/chrome/observability.d.ts +110 -0
- package/dist/types/src/utils/chrome/snapshot-plugin.d.ts +0 -3
- package/dist/types/src/utils/data/index.d.ts +0 -1
- package/package.json +4 -3
- package/dist/es/utils/data/snapshot.js +0 -82
- package/dist/lib/utils/data/snapshot.js +0 -107
- package/dist/types/src/utils/data/snapshot.d.ts +0 -3
package/dist/es/i18n/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const resources = {
|
|
|
11
11
|
proxy: "Proxy",
|
|
12
12
|
dependency: "Dependency graph",
|
|
13
13
|
share: "Shared",
|
|
14
|
+
loadingTrace: "Loading trace",
|
|
14
15
|
performance: "Performance"
|
|
15
16
|
},
|
|
16
17
|
header: {
|
|
@@ -229,6 +230,94 @@ const resources = {
|
|
|
229
230
|
shared: "Shared",
|
|
230
231
|
entry: "Entry",
|
|
231
232
|
version: "Version"
|
|
233
|
+
},
|
|
234
|
+
loadingTrace: {
|
|
235
|
+
title: "Loading Trace",
|
|
236
|
+
empty: "No loading report yet",
|
|
237
|
+
emptyEnableChrome: "No observability plugin was detected on the page. Enable Chrome observability to start collecting loading reports.",
|
|
238
|
+
status: {
|
|
239
|
+
enabled: "Observability is enabled for the current page.",
|
|
240
|
+
disabled: "Observability is not enabled for the current page.",
|
|
241
|
+
unavailable: "Current page is unavailable.",
|
|
242
|
+
reloading: "Configuration saved. Reloading current page.",
|
|
243
|
+
synced: "Reports synced.",
|
|
244
|
+
noReports: "No report found on the current page.",
|
|
245
|
+
userPlugin: "Application observability plugin detected. Syncing existing reports."
|
|
246
|
+
},
|
|
247
|
+
confirm: {
|
|
248
|
+
observeTitle: "Start observability?",
|
|
249
|
+
updateTitle: "Update configuration?",
|
|
250
|
+
content: "The current tab will reload after the configuration is saved."
|
|
251
|
+
},
|
|
252
|
+
actions: {
|
|
253
|
+
observeNow: "Observe now",
|
|
254
|
+
updateConfig: "Update config",
|
|
255
|
+
config: "Configuration",
|
|
256
|
+
disable: "Disable",
|
|
257
|
+
refresh: "Sync",
|
|
258
|
+
export: "Export",
|
|
259
|
+
confirm: "Confirm",
|
|
260
|
+
cancel: "Cancel"
|
|
261
|
+
},
|
|
262
|
+
config: {
|
|
263
|
+
level: "Level",
|
|
264
|
+
levelTip: "Controls how much event detail is kept. Verbose keeps the full timeline, summary keeps key results, and error focuses on failures.",
|
|
265
|
+
verbose: "Verbose",
|
|
266
|
+
summary: "Summary",
|
|
267
|
+
error: "Error",
|
|
268
|
+
console: "Console hints",
|
|
269
|
+
consoleTip: "Prints lightweight hints in the inspected page console. Turn it off when the page console should stay clean."
|
|
270
|
+
},
|
|
271
|
+
stats: {
|
|
272
|
+
state: "State",
|
|
273
|
+
reports: "Reports",
|
|
274
|
+
events: "Events",
|
|
275
|
+
latest: "Latest outcome",
|
|
276
|
+
customTip: "Custom means the inspected page already registered its own observability plugin, so reports are read from the page instead of only from the Chrome collection plugin."
|
|
277
|
+
},
|
|
278
|
+
reports: {
|
|
279
|
+
search: "Filter reports",
|
|
280
|
+
noMatch: "No matching report",
|
|
281
|
+
success: "Success",
|
|
282
|
+
failed: "Failed",
|
|
283
|
+
pending: "Pending",
|
|
284
|
+
recovered: "Recovered",
|
|
285
|
+
eventRecovered: "Recovered",
|
|
286
|
+
limited: "Basic observability",
|
|
287
|
+
lowVersionTip: "The current MF runtime version is too low, so only basic loading events can be collected. Fine-grained remoteEntry, init, expose, factory, and shared phases may be missing. Upgrade to 2.5.0+ for the full loading trace.",
|
|
288
|
+
unknownVersionTip: "The current MF runtime version cannot be detected, so Chrome observability may only collect basic loading events. Fine-grained remoteEntry, init, expose, factory, and shared phases may be missing."
|
|
289
|
+
},
|
|
290
|
+
currentLoad: {
|
|
291
|
+
title: "Current loading",
|
|
292
|
+
remoteReport: "Remote",
|
|
293
|
+
sharedReport: "Shared dependency",
|
|
294
|
+
consumer: "Current consumer",
|
|
295
|
+
request: "Request",
|
|
296
|
+
producer: "Producer",
|
|
297
|
+
remoteName: "Remote name",
|
|
298
|
+
expose: "Expose",
|
|
299
|
+
shared: "Shared dependency",
|
|
300
|
+
provider: "Provider",
|
|
301
|
+
requiredVersion: "Required version",
|
|
302
|
+
selectedVersion: "Selected version",
|
|
303
|
+
availableVersions: "Available versions"
|
|
304
|
+
},
|
|
305
|
+
loadedBefore: {
|
|
306
|
+
title: "Other consumer loading records",
|
|
307
|
+
consumerCount: "{{count}} consumer(s)",
|
|
308
|
+
producerLoaded: "Same producer was loaded before",
|
|
309
|
+
exposeLoaded: "Current expose was loaded before",
|
|
310
|
+
exposeNotLoaded: "Current expose was not loaded before",
|
|
311
|
+
consumer: "Consumer",
|
|
312
|
+
status: "Status",
|
|
313
|
+
exposes: "Loaded exposes",
|
|
314
|
+
unknownConsumer: "Unknown consumer",
|
|
315
|
+
entryReady: "remoteEntry is available",
|
|
316
|
+
entryMissing: "remoteEntry is not available",
|
|
317
|
+
initReady: "container was initialized",
|
|
318
|
+
initMissing: "container was not initialized",
|
|
319
|
+
noExposes: "No expose record"
|
|
320
|
+
}
|
|
232
321
|
}
|
|
233
322
|
}
|
|
234
323
|
},
|
|
@@ -240,6 +329,7 @@ const resources = {
|
|
|
240
329
|
proxy: "代理配置",
|
|
241
330
|
dependency: "依赖关系图",
|
|
242
331
|
share: "共享依赖",
|
|
332
|
+
loadingTrace: "加载追踪",
|
|
243
333
|
performance: "性能"
|
|
244
334
|
},
|
|
245
335
|
header: {
|
|
@@ -458,6 +548,94 @@ const resources = {
|
|
|
458
548
|
shared: "共享依赖",
|
|
459
549
|
entry: "入口",
|
|
460
550
|
version: "版本"
|
|
551
|
+
},
|
|
552
|
+
loadingTrace: {
|
|
553
|
+
title: "加载追踪",
|
|
554
|
+
empty: "暂无加载报告",
|
|
555
|
+
emptyEnableChrome: "当前页面未检测到观测插件。可以开启 Chrome 采集来收集加载报告。",
|
|
556
|
+
status: {
|
|
557
|
+
enabled: "当前页面已开启加载追踪。",
|
|
558
|
+
disabled: "当前页面未开启加载追踪。",
|
|
559
|
+
unavailable: "当前页面暂不可用。",
|
|
560
|
+
reloading: "配置已保存,正在刷新当前页面。",
|
|
561
|
+
synced: "报告已同步。",
|
|
562
|
+
noReports: "当前页面还没有报告。",
|
|
563
|
+
userPlugin: "已检测到页面自带观测插件,正在同步已有报告。"
|
|
564
|
+
},
|
|
565
|
+
confirm: {
|
|
566
|
+
observeTitle: "开启加载追踪?",
|
|
567
|
+
updateTitle: "更新配置?",
|
|
568
|
+
content: "保存配置后会刷新当前标签页。"
|
|
569
|
+
},
|
|
570
|
+
actions: {
|
|
571
|
+
observeNow: "开启采集",
|
|
572
|
+
updateConfig: "更新配置",
|
|
573
|
+
config: "配置",
|
|
574
|
+
disable: "关闭",
|
|
575
|
+
refresh: "同步",
|
|
576
|
+
export: "导出",
|
|
577
|
+
confirm: "确认",
|
|
578
|
+
cancel: "取消"
|
|
579
|
+
},
|
|
580
|
+
config: {
|
|
581
|
+
level: "记录级别",
|
|
582
|
+
levelTip: "控制保留多少事件细节。完整会保留完整链路,摘要只保留关键结果,错误只关注失败。",
|
|
583
|
+
verbose: "完整",
|
|
584
|
+
summary: "摘要",
|
|
585
|
+
error: "错误",
|
|
586
|
+
console: "控制台提示",
|
|
587
|
+
consoleTip: "在被调试页面的控制台打印轻量提示。如果想保持页面控制台干净,可以关闭。"
|
|
588
|
+
},
|
|
589
|
+
stats: {
|
|
590
|
+
state: "状态",
|
|
591
|
+
reports: "报告",
|
|
592
|
+
events: "事件",
|
|
593
|
+
latest: "最新结果",
|
|
594
|
+
customTip: "Custom 表示当前页面已经自己注册了观测插件,报告会从页面已有插件中读取,不只依赖 Chrome 插件注入采集。"
|
|
595
|
+
},
|
|
596
|
+
reports: {
|
|
597
|
+
search: "过滤报告",
|
|
598
|
+
noMatch: "没有匹配的报告",
|
|
599
|
+
success: "成功",
|
|
600
|
+
failed: "失败",
|
|
601
|
+
pending: "进行中",
|
|
602
|
+
recovered: "兜底成功",
|
|
603
|
+
eventRecovered: "兜底",
|
|
604
|
+
limited: "基础观测",
|
|
605
|
+
lowVersionTip: "当前 MF 运行时版本较低,只能采集基础加载事件。remoteEntry、init、expose、factory、shared 等细阶段可能缺失。升级到 2.5.0+ 后可获得完整链路。",
|
|
606
|
+
unknownVersionTip: "当前 MF 运行时版本无法识别,Chrome 观测可能只能采集基础加载事件。remoteEntry、init、expose、factory、shared 等细阶段可能缺失。"
|
|
607
|
+
},
|
|
608
|
+
currentLoad: {
|
|
609
|
+
title: "当前加载",
|
|
610
|
+
remoteReport: "远程模块",
|
|
611
|
+
sharedReport: "共享依赖",
|
|
612
|
+
consumer: "当前消费方",
|
|
613
|
+
request: "请求",
|
|
614
|
+
producer: "生产者",
|
|
615
|
+
remoteName: "生产者名称",
|
|
616
|
+
expose: "Expose",
|
|
617
|
+
shared: "共享依赖",
|
|
618
|
+
provider: "提供方",
|
|
619
|
+
requiredVersion: "要求版本",
|
|
620
|
+
selectedVersion: "实际版本",
|
|
621
|
+
availableVersions: "可用版本"
|
|
622
|
+
},
|
|
623
|
+
loadedBefore: {
|
|
624
|
+
title: "其他消费方加载记录",
|
|
625
|
+
consumerCount: "{{count}} 个消费方",
|
|
626
|
+
producerLoaded: "同一生产者之前已被加载",
|
|
627
|
+
exposeLoaded: "当前 expose 之前已被加载",
|
|
628
|
+
exposeNotLoaded: "当前 expose 之前未被加载",
|
|
629
|
+
consumer: "消费方",
|
|
630
|
+
status: "状态",
|
|
631
|
+
exposes: "已加载 expose",
|
|
632
|
+
unknownConsumer: "未知消费方",
|
|
633
|
+
entryReady: "remoteEntry 已拿到",
|
|
634
|
+
entryMissing: "remoteEntry 未拿到",
|
|
635
|
+
initReady: "容器已初始化",
|
|
636
|
+
initMissing: "容器未初始化",
|
|
637
|
+
noExposes: "暂无导出记录"
|
|
638
|
+
}
|
|
461
639
|
}
|
|
462
640
|
}
|
|
463
641
|
}
|
|
@@ -70,10 +70,11 @@ const syncActiveTab = (tabId) => __async(void 0, null, function* () {
|
|
|
70
70
|
setTargetTab(tab);
|
|
71
71
|
return tab;
|
|
72
72
|
}
|
|
73
|
-
const
|
|
73
|
+
const tabs = yield getTabs({
|
|
74
74
|
active: true,
|
|
75
75
|
lastFocusedWindow: true
|
|
76
76
|
});
|
|
77
|
+
const activeTab = Array.isArray(tabs) ? tabs[0] : void 0;
|
|
77
78
|
setTargetTab(activeTab);
|
|
78
79
|
return activeTab;
|
|
79
80
|
} catch (error) {
|
|
@@ -96,9 +97,7 @@ function getInspectWindowTabId() {
|
|
|
96
97
|
function(info, error) {
|
|
97
98
|
const { tabId } = chrome.devtools.inspectedWindow;
|
|
98
99
|
getTabs().then((tabs) => {
|
|
99
|
-
const target = tabs.find(
|
|
100
|
-
(tab) => tab.id === tabId
|
|
101
|
-
);
|
|
100
|
+
const target = Array.isArray(tabs) ? tabs.find((tab) => tab.id === tabId) : void 0;
|
|
102
101
|
setTargetTab(target);
|
|
103
102
|
});
|
|
104
103
|
console.log(
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
const MESSAGE_OPEN_SIDE_PANEL = "mf-devtools/open-side-panel";
|
|
2
2
|
const MESSAGE_ACTIVE_TAB_CHANGED = "mf-devtools/active-tab-changed";
|
|
3
|
+
const MESSAGE_OBSERVABILITY_DEVTOOLS_EVENT = "mf-devtools/observability-event";
|
|
4
|
+
const OBSERVABILITY_DEVTOOLS_SOURCE = "module-federation/observability";
|
|
5
|
+
const OBSERVABILITY_DEVTOOLS_STORAGE_KEY = "__MF_DEVTOOLS_OBSERVABILITY_CONFIG__";
|
|
3
6
|
export {
|
|
4
7
|
MESSAGE_ACTIVE_TAB_CHANGED,
|
|
5
|
-
|
|
8
|
+
MESSAGE_OBSERVABILITY_DEVTOOLS_EVENT,
|
|
9
|
+
MESSAGE_OPEN_SIDE_PANEL,
|
|
10
|
+
OBSERVABILITY_DEVTOOLS_SOURCE,
|
|
11
|
+
OBSERVABILITY_DEVTOOLS_STORAGE_KEY
|
|
6
12
|
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChromeObservabilityPlugin
|
|
3
|
+
} from "@module-federation/observability-plugin/chrome-devtool";
|
|
4
|
+
import {
|
|
5
|
+
OBSERVABILITY_DEVTOOLS_SOURCE,
|
|
6
|
+
OBSERVABILITY_DEVTOOLS_STORAGE_KEY
|
|
7
|
+
} from "./messages";
|
|
8
|
+
import {
|
|
9
|
+
createObservabilityPluginOptions,
|
|
10
|
+
normalizeObservabilityDevtoolsConfig
|
|
11
|
+
} from "./observability-shared";
|
|
12
|
+
const DEVTOOLS_PLUGIN_NAME = "observability-plugin:chrome-extension";
|
|
13
|
+
const LEGACY_DEVTOOLS_PLUGIN_NAME = "observability-plugin-devtools";
|
|
14
|
+
const getFederationWindow = () => window;
|
|
15
|
+
const safeReadStoredConfig = () => {
|
|
16
|
+
var _a;
|
|
17
|
+
try {
|
|
18
|
+
const raw = (_a = window.localStorage) == null ? void 0 : _a.getItem(
|
|
19
|
+
OBSERVABILITY_DEVTOOLS_STORAGE_KEY
|
|
20
|
+
);
|
|
21
|
+
if (!raw) {
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
return normalizeObservabilityDevtoolsConfig(JSON.parse(raw));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const defineWritableGlobal = (key, value) => {
|
|
30
|
+
const targetWindow = getFederationWindow();
|
|
31
|
+
try {
|
|
32
|
+
Object.defineProperty(targetWindow, key, {
|
|
33
|
+
value,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true
|
|
36
|
+
});
|
|
37
|
+
} catch (e) {
|
|
38
|
+
targetWindow[key] = value;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const ensureFederationGlobal = () => {
|
|
42
|
+
var _a;
|
|
43
|
+
const targetWindow = getFederationWindow();
|
|
44
|
+
const federation = targetWindow.__FEDERATION__ || targetWindow.__VMOK__ || {};
|
|
45
|
+
if (!targetWindow.__FEDERATION__) {
|
|
46
|
+
defineWritableGlobal("__FEDERATION__", federation);
|
|
47
|
+
}
|
|
48
|
+
if (!targetWindow.__VMOK__) {
|
|
49
|
+
defineWritableGlobal("__VMOK__", targetWindow.__FEDERATION__);
|
|
50
|
+
}
|
|
51
|
+
if (!((_a = targetWindow.__FEDERATION__) == null ? void 0 : _a.__GLOBAL_PLUGIN__)) {
|
|
52
|
+
targetWindow.__FEDERATION__ = targetWindow.__FEDERATION__ || federation;
|
|
53
|
+
targetWindow.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
54
|
+
}
|
|
55
|
+
return targetWindow.__FEDERATION__;
|
|
56
|
+
};
|
|
57
|
+
const notifyInstalled = (status, reason, config) => {
|
|
58
|
+
try {
|
|
59
|
+
window.postMessage(
|
|
60
|
+
{
|
|
61
|
+
schemaVersion: 1,
|
|
62
|
+
source: OBSERVABILITY_DEVTOOLS_SOURCE,
|
|
63
|
+
kind: status,
|
|
64
|
+
reason,
|
|
65
|
+
config,
|
|
66
|
+
createdAt: Date.now()
|
|
67
|
+
},
|
|
68
|
+
"*"
|
|
69
|
+
);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const install = () => {
|
|
74
|
+
const config = safeReadStoredConfig();
|
|
75
|
+
if (!(config == null ? void 0 : config.enabled)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const federation = ensureFederationGlobal();
|
|
79
|
+
const globalPlugins = (federation == null ? void 0 : federation.__GLOBAL_PLUGIN__) || [];
|
|
80
|
+
if (globalPlugins.some(
|
|
81
|
+
(plugin2) => (plugin2 == null ? void 0 : plugin2.name) === DEVTOOLS_PLUGIN_NAME || (plugin2 == null ? void 0 : plugin2.name) === LEGACY_DEVTOOLS_PLUGIN_NAME
|
|
82
|
+
)) {
|
|
83
|
+
notifyInstalled("skipped", "already-installed", config);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const plugin = ChromeObservabilityPlugin(
|
|
87
|
+
createObservabilityPluginOptions(config)
|
|
88
|
+
);
|
|
89
|
+
globalPlugins.push(plugin);
|
|
90
|
+
federation.__GLOBAL_PLUGIN__ = globalPlugins;
|
|
91
|
+
notifyInstalled("installed", void 0, config);
|
|
92
|
+
};
|
|
93
|
+
install();
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { OBSERVABILITY_DEVTOOLS_SOURCE } from "./messages";
|
|
2
|
+
const CHROME_OBSERVABILITY_SCOPE = "chrome_extension";
|
|
3
|
+
const MIN_EVENTS = 10;
|
|
4
|
+
const MAX_EVENTS = 1e3;
|
|
5
|
+
const DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG = {
|
|
6
|
+
enabled: true,
|
|
7
|
+
level: "verbose",
|
|
8
|
+
maxEvents: 300,
|
|
9
|
+
console: true,
|
|
10
|
+
browser: {
|
|
11
|
+
enabled: true,
|
|
12
|
+
scope: CHROME_OBSERVABILITY_SCOPE,
|
|
13
|
+
mode: "development"
|
|
14
|
+
},
|
|
15
|
+
trace: {
|
|
16
|
+
printStart: true
|
|
17
|
+
},
|
|
18
|
+
react: {
|
|
19
|
+
injectLoadedCallback: false,
|
|
20
|
+
remoteIds: []
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const isObject = (value) => typeof value === "object" && value !== null;
|
|
24
|
+
const normalizeBoolean = (value, fallback) => typeof value === "boolean" ? value : fallback;
|
|
25
|
+
const normalizeLevel = (value) => value === "error" || value === "summary" || value === "verbose" ? value : DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.level;
|
|
26
|
+
const normalizeMode = (value) => value === "production" || value === "development" ? value : DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.browser.mode;
|
|
27
|
+
const normalizeMaxEvents = (value) => {
|
|
28
|
+
const parsed = Number(value);
|
|
29
|
+
if (!Number.isFinite(parsed)) {
|
|
30
|
+
return DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.maxEvents;
|
|
31
|
+
}
|
|
32
|
+
return Math.max(MIN_EVENTS, Math.min(MAX_EVENTS, Math.floor(parsed)));
|
|
33
|
+
};
|
|
34
|
+
const normalizeScope = (value) => {
|
|
35
|
+
if (typeof value !== "string") {
|
|
36
|
+
return CHROME_OBSERVABILITY_SCOPE;
|
|
37
|
+
}
|
|
38
|
+
const trimmed = value.trim().replace(/[^\w:@.-]+/g, "-");
|
|
39
|
+
return trimmed || CHROME_OBSERVABILITY_SCOPE;
|
|
40
|
+
};
|
|
41
|
+
const normalizeObservabilityDevtoolsConfig = (value) => {
|
|
42
|
+
const source = isObject(value) ? value : {};
|
|
43
|
+
const browser = isObject(source.browser) ? source.browser : {};
|
|
44
|
+
const trace = isObject(source.trace) ? source.trace : {};
|
|
45
|
+
return {
|
|
46
|
+
enabled: normalizeBoolean(
|
|
47
|
+
source.enabled,
|
|
48
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.enabled
|
|
49
|
+
),
|
|
50
|
+
level: normalizeLevel(source.level),
|
|
51
|
+
maxEvents: normalizeMaxEvents(source.maxEvents),
|
|
52
|
+
console: normalizeBoolean(
|
|
53
|
+
source.console,
|
|
54
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.console
|
|
55
|
+
),
|
|
56
|
+
browser: {
|
|
57
|
+
enabled: normalizeBoolean(
|
|
58
|
+
browser.enabled,
|
|
59
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.browser.enabled
|
|
60
|
+
),
|
|
61
|
+
scope: normalizeScope(browser.scope),
|
|
62
|
+
mode: normalizeMode(browser.mode)
|
|
63
|
+
},
|
|
64
|
+
trace: {
|
|
65
|
+
printStart: normalizeBoolean(
|
|
66
|
+
trace.printStart,
|
|
67
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG.trace.printStart
|
|
68
|
+
)
|
|
69
|
+
},
|
|
70
|
+
react: {
|
|
71
|
+
injectLoadedCallback: false,
|
|
72
|
+
remoteIds: []
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
const createObservabilityPluginOptions = (config) => ({
|
|
77
|
+
enabled: config.enabled,
|
|
78
|
+
level: config.level,
|
|
79
|
+
maxEvents: config.maxEvents,
|
|
80
|
+
console: config.console,
|
|
81
|
+
browser: {
|
|
82
|
+
enabled: config.browser.enabled,
|
|
83
|
+
scope: config.browser.scope,
|
|
84
|
+
mode: config.browser.mode
|
|
85
|
+
},
|
|
86
|
+
trace: {
|
|
87
|
+
printStart: config.trace.printStart
|
|
88
|
+
},
|
|
89
|
+
devtools: {
|
|
90
|
+
enabled: true,
|
|
91
|
+
source: OBSERVABILITY_DEVTOOLS_SOURCE
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
export {
|
|
95
|
+
CHROME_OBSERVABILITY_SCOPE,
|
|
96
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG,
|
|
97
|
+
createObservabilityPluginOptions,
|
|
98
|
+
normalizeObservabilityDevtoolsConfig
|
|
99
|
+
};
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import { injectScript } from "./index";
|
|
22
|
+
import { OBSERVABILITY_DEVTOOLS_STORAGE_KEY } from "./messages";
|
|
23
|
+
import {
|
|
24
|
+
CHROME_OBSERVABILITY_SCOPE,
|
|
25
|
+
DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG,
|
|
26
|
+
normalizeObservabilityDevtoolsConfig
|
|
27
|
+
} from "./observability-shared";
|
|
28
|
+
const USER_OBSERVABILITY_PLUGIN_NAME = "observability-plugin";
|
|
29
|
+
const CHROME_OBSERVABILITY_PLUGIN_NAME = "observability-plugin:chrome-extension";
|
|
30
|
+
const LEGACY_CHROME_OBSERVABILITY_PLUGIN_NAME = "observability-plugin-devtools";
|
|
31
|
+
const OBSERVABILITY_SNAPSHOT_CONTEXT = {
|
|
32
|
+
chromeScope: CHROME_OBSERVABILITY_SCOPE,
|
|
33
|
+
userPluginName: USER_OBSERVABILITY_PLUGIN_NAME,
|
|
34
|
+
chromePluginNames: [
|
|
35
|
+
CHROME_OBSERVABILITY_PLUGIN_NAME,
|
|
36
|
+
LEGACY_CHROME_OBSERVABILITY_PLUGIN_NAME
|
|
37
|
+
]
|
|
38
|
+
};
|
|
39
|
+
const readConfigFromPage = (storageKey) => {
|
|
40
|
+
var _a;
|
|
41
|
+
try {
|
|
42
|
+
const raw = (_a = window.localStorage) == null ? void 0 : _a.getItem(storageKey);
|
|
43
|
+
return raw ? JSON.parse(raw) : null;
|
|
44
|
+
} catch (e) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const writeConfigToPage = (storageKey, config) => {
|
|
49
|
+
var _a;
|
|
50
|
+
(_a = window.localStorage) == null ? void 0 : _a.setItem(storageKey, JSON.stringify(config));
|
|
51
|
+
return config;
|
|
52
|
+
};
|
|
53
|
+
const removeConfigFromPage = (storageKey) => {
|
|
54
|
+
var _a;
|
|
55
|
+
(_a = window.localStorage) == null ? void 0 : _a.removeItem(storageKey);
|
|
56
|
+
return true;
|
|
57
|
+
};
|
|
58
|
+
const reloadPage = () => {
|
|
59
|
+
var _a;
|
|
60
|
+
(_a = globalThis.location) == null ? void 0 : _a.reload();
|
|
61
|
+
};
|
|
62
|
+
const readSnapshotFromPage = (storageKey, context) => {
|
|
63
|
+
const chromeScope = typeof (context == null ? void 0 : context.chromeScope) === "string" ? context.chromeScope : "chrome_extension";
|
|
64
|
+
const userPluginName = typeof (context == null ? void 0 : context.userPluginName) === "string" ? context.userPluginName : "observability-plugin";
|
|
65
|
+
const chromePluginNames = Array.isArray(context == null ? void 0 : context.chromePluginNames) ? context.chromePluginNames : [
|
|
66
|
+
"observability-plugin:chrome-extension",
|
|
67
|
+
"observability-plugin-devtools"
|
|
68
|
+
];
|
|
69
|
+
const safeCopy = (value) => {
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(JSON.stringify(value));
|
|
72
|
+
} catch (e) {
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const rawConfig = (() => {
|
|
77
|
+
var _a;
|
|
78
|
+
try {
|
|
79
|
+
const raw = (_a = window.localStorage) == null ? void 0 : _a.getItem(storageKey);
|
|
80
|
+
return raw ? JSON.parse(raw) : null;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
const federation = window.__FEDERATION__ || window.__VMOK__;
|
|
86
|
+
const readers = (federation == null ? void 0 : federation.__OBSERVABILITY__) || {};
|
|
87
|
+
const reports = [];
|
|
88
|
+
const scopes = Object.keys(readers);
|
|
89
|
+
const isChromeObservabilityPluginName = (name) => chromePluginNames.includes(String(name));
|
|
90
|
+
const hasUserObservabilityPluginFromInstances = Array.isArray(
|
|
91
|
+
federation == null ? void 0 : federation.__INSTANCES__
|
|
92
|
+
) ? federation.__INSTANCES__.some((instance) => {
|
|
93
|
+
var _a;
|
|
94
|
+
const plugins = (_a = instance == null ? void 0 : instance.options) == null ? void 0 : _a.plugins;
|
|
95
|
+
if (!Array.isArray(plugins)) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return plugins.some(
|
|
99
|
+
(plugin) => (plugin == null ? void 0 : plugin.name) === userPluginName && !isChromeObservabilityPluginName(plugin == null ? void 0 : plugin.name)
|
|
100
|
+
);
|
|
101
|
+
}) : false;
|
|
102
|
+
const hasUserObservabilityPluginFromReaders = scopes.some(
|
|
103
|
+
(scope) => scope !== chromeScope
|
|
104
|
+
);
|
|
105
|
+
scopes.forEach((scope) => {
|
|
106
|
+
const reader = readers[scope];
|
|
107
|
+
if (!reader || typeof reader.getReports !== "function") {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const scopeReports = reader.getReports({ limit: 100 });
|
|
112
|
+
if (!Array.isArray(scopeReports)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
scopeReports.forEach((report) => {
|
|
116
|
+
const copied = safeCopy(report);
|
|
117
|
+
if (copied == null ? void 0 : copied.traceId) {
|
|
118
|
+
copied.__scope = scope;
|
|
119
|
+
reports.push(copied);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
} catch (e) {
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
config: rawConfig,
|
|
127
|
+
stored: Boolean(rawConfig),
|
|
128
|
+
scopes,
|
|
129
|
+
reports,
|
|
130
|
+
hasUserObservabilityPlugin: hasUserObservabilityPluginFromInstances || hasUserObservabilityPluginFromReaders
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
const readObservabilityConfig = () => __async(void 0, null, function* () {
|
|
134
|
+
const config = yield injectScript(
|
|
135
|
+
readConfigFromPage,
|
|
136
|
+
false,
|
|
137
|
+
OBSERVABILITY_DEVTOOLS_STORAGE_KEY
|
|
138
|
+
);
|
|
139
|
+
return normalizeObservabilityDevtoolsConfig(
|
|
140
|
+
config || DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
const applyObservabilityConfig = (config) => __async(void 0, null, function* () {
|
|
144
|
+
return injectScript(
|
|
145
|
+
writeConfigToPage,
|
|
146
|
+
false,
|
|
147
|
+
OBSERVABILITY_DEVTOOLS_STORAGE_KEY,
|
|
148
|
+
normalizeObservabilityDevtoolsConfig(config)
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
const disableObservabilityConfig = () => __async(void 0, null, function* () {
|
|
152
|
+
return injectScript(removeConfigFromPage, false, OBSERVABILITY_DEVTOOLS_STORAGE_KEY);
|
|
153
|
+
});
|
|
154
|
+
const reloadInspectedPage = () => __async(void 0, null, function* () {
|
|
155
|
+
return injectScript(reloadPage, false);
|
|
156
|
+
});
|
|
157
|
+
const readObservabilitySnapshot = () => __async(void 0, null, function* () {
|
|
158
|
+
const snapshot = yield injectScript(
|
|
159
|
+
readSnapshotFromPage,
|
|
160
|
+
true,
|
|
161
|
+
OBSERVABILITY_DEVTOOLS_STORAGE_KEY,
|
|
162
|
+
OBSERVABILITY_SNAPSHOT_CONTEXT
|
|
163
|
+
);
|
|
164
|
+
return {
|
|
165
|
+
config: normalizeObservabilityDevtoolsConfig(
|
|
166
|
+
(snapshot == null ? void 0 : snapshot.config) || DEFAULT_OBSERVABILITY_DEVTOOLS_CONFIG
|
|
167
|
+
),
|
|
168
|
+
stored: Boolean(snapshot == null ? void 0 : snapshot.stored),
|
|
169
|
+
scopes: Array.isArray(snapshot == null ? void 0 : snapshot.scopes) ? snapshot.scopes : [],
|
|
170
|
+
reports: Array.isArray(snapshot == null ? void 0 : snapshot.reports) ? snapshot.reports : [],
|
|
171
|
+
hasUserObservabilityPlugin: Boolean(snapshot == null ? void 0 : snapshot.hasUserObservabilityPlugin)
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
const mergeObservabilityReports = (currentReports, incomingReports) => {
|
|
175
|
+
const merged = /* @__PURE__ */ new Map();
|
|
176
|
+
currentReports.forEach((report) => {
|
|
177
|
+
if (report.traceId) {
|
|
178
|
+
merged.set(report.traceId, report);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
incomingReports.forEach((report) => {
|
|
182
|
+
if (report.traceId) {
|
|
183
|
+
merged.set(report.traceId, report);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
return Array.from(merged.values()).sort((left, right) => {
|
|
187
|
+
if ((right.updatedAt || 0) !== (left.updatedAt || 0)) {
|
|
188
|
+
return (right.updatedAt || 0) - (left.updatedAt || 0);
|
|
189
|
+
}
|
|
190
|
+
return (right.startedAt || 0) - (left.startedAt || 0);
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
const getObservabilityReportScopeLabel = (report) => {
|
|
194
|
+
const scope = report.__scope;
|
|
195
|
+
if (!scope || scope === CHROME_OBSERVABILITY_SCOPE) {
|
|
196
|
+
return void 0;
|
|
197
|
+
}
|
|
198
|
+
return `custom: ${scope}`;
|
|
199
|
+
};
|
|
200
|
+
export {
|
|
201
|
+
applyObservabilityConfig,
|
|
202
|
+
disableObservabilityConfig,
|
|
203
|
+
getObservabilityReportScopeLabel,
|
|
204
|
+
mergeObservabilityReports,
|
|
205
|
+
readObservabilityConfig,
|
|
206
|
+
readObservabilitySnapshot,
|
|
207
|
+
reloadInspectedPage
|
|
208
|
+
};
|
|
@@ -1,42 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { MODULE_DEVTOOL_IDENTIFIER } from "@module-federation/sdk";
|
|
4
|
-
import { definePropertyGlobalVal } from "../sdk";
|
|
5
|
-
const chromeOverrideRemotesPlugin = function() {
|
|
6
|
-
return {
|
|
7
|
-
name: "mf-chrome-devtools-override-remotes-plugin",
|
|
8
|
-
beforeRegisterRemote(args) {
|
|
9
|
-
try {
|
|
10
|
-
const { remote } = args;
|
|
11
|
-
const overrideRemote = runtimeHelpers.global.nativeGlobal.localStorage.getItem(
|
|
12
|
-
MODULE_DEVTOOL_IDENTIFIER
|
|
13
|
-
);
|
|
14
|
-
if (!overrideRemote) {
|
|
15
|
-
return args;
|
|
16
|
-
}
|
|
17
|
-
const parsedOverrideRemote = JSON.parse(overrideRemote);
|
|
18
|
-
const overrideEntryOrVersion = parsedOverrideRemote[remote.name];
|
|
19
|
-
if (overrideEntryOrVersion) {
|
|
20
|
-
if (overrideEntryOrVersion.startsWith("http")) {
|
|
21
|
-
delete remote.version;
|
|
22
|
-
remote.entry = overrideEntryOrVersion;
|
|
23
|
-
} else {
|
|
24
|
-
delete remote.entry;
|
|
25
|
-
remote.version = overrideEntryOrVersion;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
} catch (e) {
|
|
29
|
-
console.error(e);
|
|
30
|
-
}
|
|
31
|
-
return args;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
if (!(window == null ? void 0 : window.__FEDERATION__)) {
|
|
36
|
-
definePropertyGlobalVal(window, "__FEDERATION__", {});
|
|
37
|
-
definePropertyGlobalVal(window, "__VMOK__", window.__FEDERATION__);
|
|
38
|
-
}
|
|
39
|
-
if (!(window == null ? void 0 : window.__FEDERATION__.__GLOBAL_PLUGIN__)) {
|
|
40
|
-
window.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
|
|
41
|
-
}
|
|
42
|
-
(_a = window.__FEDERATION__.__GLOBAL_PLUGIN__) == null ? void 0 : _a.push(chromeOverrideRemotesPlugin());
|
|
1
|
+
const basicProxyCore = require("../../vendor/basic-proxy-core.js");
|
|
2
|
+
basicProxyCore.registerOverridePlugin(globalThis);
|