forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowserModuleCollector.ts
More file actions
37 lines (34 loc) · 1015 Bytes
/
BrowserModuleCollector.ts
File metadata and controls
37 lines (34 loc) · 1015 Bytes
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
import {
getHashCode,
IModuleCollector,
ModuleInfo,
parseVersion,
} from "@exceptionless/core";
export class BrowserModuleCollector implements IModuleCollector {
public getModules(): ModuleInfo[] {
if (!document || !document.getElementsByTagName) {
return null;
}
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: 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;
}
}