forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowserRequestInfoCollector.ts
More file actions
45 lines (39 loc) · 1.16 KB
/
BrowserRequestInfoCollector.ts
File metadata and controls
45 lines (39 loc) · 1.16 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
import {
EventPluginContext,
getCookies,
IRequestInfoCollector,
parseQueryString,
RequestInfo,
} from "@exceptionless/core";
export class BrowserRequestInfoCollector implements IRequestInfoCollector {
public getRequestInfo(context: EventPluginContext): RequestInfo {
if (!document || !navigator || !location) {
return null;
}
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);
}
if (config.includeQueryString) {
requestInfo.query_string = parseQueryString(
location.search.substring(1),
exclusions,
);
}
if (document.referrer && document.referrer !== "") {
requestInfo.referrer = document.referrer;
}
return requestInfo;
}
}