forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowserExceptionlessClient.ts
More file actions
66 lines (55 loc) · 2.45 KB
/
BrowserExceptionlessClient.ts
File metadata and controls
66 lines (55 loc) · 2.45 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
61
62
63
64
65
66
import {
ExceptionlessClient,
parseQueryString
} from "@exceptionless/core";
import { BrowserConfiguration } from "./configuration/BrowserConfiguration.js";
import { BrowserGlobalHandlerPlugin } from "./plugins/BrowserGlobalHandlerPlugin.js";
import { BrowserLifeCyclePlugin } from "./plugins/BrowserLifeCyclePlugin.js";
import { BrowserWrapFunctions } from "./plugins/BrowserWrapFunctions.js";
import { BrowserErrorParser } from "./services/BrowserErrorParser.js";
import { BrowserModuleCollector } from "./services/BrowserModuleCollector.js";
import { BrowserRequestInfoCollector } from "./services/BrowserRequestInfoCollector.js";
import { BrowserFetchSubmissionClient } from "./submission/BrowserFetchSubmissionClient.js";
export class BrowserExceptionlessClient extends ExceptionlessClient {
constructor() {
super(new BrowserConfiguration());
}
public async startup(configurationOrApiKey?: (config: BrowserConfiguration) => void | string): Promise<void> {
const config = this.config;
if (configurationOrApiKey) {
const settings = this.getDefaultsSettingsFromScriptTag();
if (settings?.apiKey) {
config.apiKey = settings.apiKey;
}
if (settings?.serverUrl) {
config.serverUrl = settings.serverUrl;
}
if (settings?.serverUrl) {
config.serverUrl = settings.serverUrl;
}
if (settings?.includePrivateInformation) {
config.includePrivateInformation = settings.includePrivateInformation === "true";
}
config.addPlugin(new BrowserGlobalHandlerPlugin());
config.addPlugin(new BrowserLifeCyclePlugin());
config.addPlugin(new BrowserWrapFunctions());
config.services.errorParser = new BrowserErrorParser();
config.services.moduleCollector = new BrowserModuleCollector();
config.services.requestInfoCollector = new BrowserRequestInfoCollector();
config.services.submissionClient = new BrowserFetchSubmissionClient(config);
}
await super.startup(configurationOrApiKey);
}
private getDefaultsSettingsFromScriptTag(): { [key: string]: string } {
if (typeof document === "undefined" || !document || !document.getElementsByTagName) {
return null;
}
const scripts = document.getElementsByTagName("script");
for (let index = 0; index < scripts.length; index++) {
if (scripts[index].src?.includes("/exceptionless")) {
return parseQueryString(scripts[index].src.split("?").pop());
}
}
return null;
}
}