Skip to content

Commit b62f2e3

Browse files
committed
fix: resolves process undefined and logs more data for browser types
1 parent bba820b commit b62f2e3

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

examples/browser-prerecorded/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<script src="../../dist/umd/deepgram.js"></script>
55
<script>
66
const { createClient } = deepgram;
7-
const _deepgram = createClient("deepgram-api-key", {
7+
const _deepgram = createClient("3d75575499a7908f7f01483469c8105897e37c1a", {
88
global: {
99
fetch: {
1010
options: {
@@ -26,7 +26,7 @@
2626
}
2727
);
2828

29-
if (error) throw error;
29+
if (error) console.error(error, result);
3030
if (!error) console.dir(result, { depth: null });
3131
};
3232

@@ -38,7 +38,7 @@
3838
}
3939
);
4040

41-
if (error) throw error;
41+
if (error) console.error(error, result);
4242
if (!error) console.dir(result, { depth: null });
4343
};
4444

src/lib/constants.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@ import { convertProtocolToWs, isBrowser } from "./helpers";
22
import { version } from "./version";
33
import type { DefaultNamespaceOptions, DefaultClientOptions } from "./types";
44

5-
export const NODE_VERSION = process.versions.node;
5+
export const NODE_VERSION =
6+
typeof process !== "undefined" && process.versions && process.versions.node
7+
? process.versions.node
8+
: "unknown";
9+
10+
export const BROWSER_AGENT =
11+
typeof window !== "undefined" && window.navigator && window.navigator.userAgent
12+
? window.navigator.userAgent
13+
: "unknown";
614

715
export const DEFAULT_HEADERS = {
816
"Content-Type": `application/json`,
917
"X-Client-Info": `@deepgram/sdk; ${isBrowser() ? "browser" : "server"}; v${version}`,
10-
"User-Agent": `@deepgram/sdk/${version} ${isBrowser() ? "javascript" : `node/${NODE_VERSION}`}`,
18+
"User-Agent": `@deepgram/sdk/${version} ${
19+
isBrowser() ? `javascript ${BROWSER_AGENT}` : `node/${NODE_VERSION}`
20+
}`,
1121
};
1222

1323
export const DEFAULT_URL = "https://api.deepgram.com";

webpack.config.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const path = require("path");
2-
const webpack = require("webpack");
32

43
module.exports = {
54
entry: "./src/index.ts",
@@ -25,9 +24,4 @@ module.exports = {
2524
resolve: {
2625
extensions: [".ts", ".js", ".json"],
2726
},
28-
plugins: [
29-
new webpack.DefinePlugin({
30-
"process.versions.node": JSON.stringify(process.versions.node),
31-
}),
32-
],
3327
};

0 commit comments

Comments
 (0)