Skip to content

Commit 5c9eed0

Browse files
committed
Added the ability to get the api key and server url from the script tag.
1 parent ef4577c commit 5c9eed0

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/exceptionless.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ module Exceptionless {
1111
export class ExceptionlessClient {
1212
public config:Configuration;
1313

14-
constructor(apiKey:string, serverUrl?:string) {
15-
this.config = new Configuration(apiKey, serverUrl);
14+
constructor(apiKey?:string, serverUrl?:string) {
15+
var settings = this.getSettingsFromScriptTag() || {};
16+
this.config = new Configuration(apiKey || settings.apiKey, serverUrl || settings.serverUrl);
1617
}
1718

1819
public createException(exception:Error): EventBuilder {
@@ -171,6 +172,18 @@ module Exceptionless {
171172
}
172173
}
173174

175+
private getSettingsFromScriptTag(): any {
176+
var scripts = document.getElementsByTagName('script');
177+
178+
for (var index = 0; index < scripts.length; index++) {
179+
if (scripts[index].src && scripts[index].src.indexOf('/exceptionless') > -1) {
180+
return Utils.parseQueryString(scripts[index].src.split('?').pop());
181+
}
182+
}
183+
184+
return null;
185+
}
186+
174187
private static _instance:ExceptionlessClient = null;
175188
public static get default() {
176189
if(ExceptionlessClient._instance === null) {

0 commit comments

Comments
 (0)