forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowserRequestInfoPlugin.ts
More file actions
66 lines (57 loc) · 1.91 KB
/
BrowserRequestInfoPlugin.ts
File metadata and controls
66 lines (57 loc) · 1.91 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 {
EventPluginContext,
getCookies,
IEventPlugin,
isMatch,
KnownEventDataKeys,
parseQueryString,
RequestInfo,
} from "@exceptionless/core";
export class BrowserRequestInfoPlugin implements IEventPlugin {
public priority: number = 70;
public name: string = "BrowserRequestInfoPlugin";
public run(context: EventPluginContext): Promise<void> {
if (context.event.data && !context.event.data[KnownEventDataKeys.RequestInfo]) {
const requestInfo: RequestInfo | undefined = this.getRequestInfo(context);
if (requestInfo) {
if (isMatch(requestInfo.user_agent, context.client.config.userAgentBotPatterns)) {
context.log.info("Cancelling event as the request user agent matches a known bot pattern");
context.cancelled = true;
} else {
context.event.data[KnownEventDataKeys.RequestInfo] = requestInfo;
}
}
}
return Promise.resolve();
}
private getRequestInfo(context: EventPluginContext): RequestInfo | undefined {
if (!document || !navigator || !location) {
return;
}
const config = context.client.config;
const exclusions = config.dataExclusions;
const requestInfo: RequestInfo = {
user_agent: navigator.userAgent,
is_secure: location.protocol === "https:",
host: location.hostname,
port: location.port && location.port !== ""
? parseInt(location.port, 10)
: 80,
path: location.pathname,
// client_ip_address: "TODO"
};
if (config.includeCookies) {
requestInfo.cookies = getCookies(document.cookie, exclusions) as Record<string, string>;
}
if (config.includeQueryString) {
requestInfo.query_string = parseQueryString(
location.search.substring(1),
exclusions,
);
}
if (document.referrer && document.referrer !== "") {
requestInfo.referrer = document.referrer;
}
return requestInfo;
}
}