forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowserModuleInfoPlugin.ts
More file actions
60 lines (52 loc) · 1.57 KB
/
BrowserModuleInfoPlugin.ts
File metadata and controls
60 lines (52 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {
EventPluginContext,
getHashCode,
IEventPlugin,
KnownEventDataKeys,
ModuleInfo,
parseVersion
} from "@exceptionless/core";
export class BrowserModuleInfoPlugin implements IEventPlugin {
public priority: number = 50;
public name: string = "BrowserModuleInfoPlugin";
private _modules: ModuleInfo[] | undefined;
public startup(): Promise<void> {
if (!this._modules) {
this._modules = this.getModules();
}
return Promise.resolve();
}
public run(context: EventPluginContext): Promise<void> {
const error = context.event.data?.[KnownEventDataKeys.Error];
if (error && !error?.modules && this._modules?.length) {
error.modules = this._modules;
}
return Promise.resolve();
}
private getModules(): ModuleInfo[] | undefined {
if (!document || !document.getElementsByTagName) {
return;
}
const modules: ModuleInfo[] = [];
const scripts: HTMLCollectionOf<HTMLScriptElement> = document
.getElementsByTagName("script");
if (scripts && scripts.length > 0) {
for (let index = 0; index < scripts.length; index++) {
if (scripts[index].src) {
modules.push({
module_id: index,
name: scripts[index].src.split("?")[0],
version: <string>parseVersion(scripts[index].src),
});
} else if (scripts[index].innerHTML) {
modules.push({
module_id: index,
name: "Script Tag",
version: getHashCode(scripts[index].innerHTML).toString(),
});
}
}
}
return modules;
}
}