You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: QUICKSTART.md
+26-36Lines changed: 26 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,71 +1,54 @@
1
1
# Quick Start Guide – CDPLogger Client
2
2
3
-
This guide demonstrates how to get started with the CDPLogger Client in both **Node.js** and **Browser** environments. Note that the client module must be built differently for each target environment.
3
+
This guide demonstrates how to get started with the CDPLogger Client in both **Node.js** and **Browser** environments. The client automatically detects the environment and works seamlessly in both.
4
4
5
5
## Documentation
6
6
7
7
For documentation on the JS logger client see [DOCUMENTATION.md](DOCUMENTATION.md)
8
8
9
9
## Overview
10
10
11
-
-**Node.js Version:**
12
-
- Uses CommonJS modules (imported via `require()`).
13
-
- Loads protobuf definitions from local files (e.g. from `./generated/containerPb.js`).
14
-
- Requires a WebSocket polyfill (such as the `ws` package) since Node.js lacks a native WebSocket.
11
+
The CDPLogger Client uses **automatic environment detection** to work in both Node.js and browser environments from a single source file:
15
12
16
-
-**Browser Version:**
17
-
- Uses the browser's native WebSocket.
18
-
- Obtains protobuf definitions from the global scope via `window.root` (set by including `containerPb.js`).
13
+
-**Node.js:**
14
+
- Automatically loads protobuf definitions using `require('./generated/containerPb.js')`
15
+
- Uses the `ws` package for WebSocket functionality (installed as a dependency)
16
+
- No manual setup required
17
+
18
+
-**Browser:**
19
+
- Uses the browser's native WebSocket API
20
+
- Expects protobuf definitions to be available at `window.root`
21
+
- Requires including the containerPb.js script before the client
19
22
20
23
## Installation
21
24
22
25
### For Node.js
23
26
24
-
Install the CDPLogger Client and a WebSocket polyfill (for the Node.js version):
25
-
26
27
```bash
27
-
npm install cdplogger-client ws
28
+
npm install cdplogger-client
28
29
```
29
30
30
31
### For Browser
31
32
32
33
Include the following scripts in your HTML:
33
34
-`protobuf.min.js` – for the ProtoBuf runtime.
34
-
-`containerPb.js` – which sets up `window.root` with your protobuf definitions.
35
-
- The web version of `client.js` – which should include the web-specific modifications (see the "Adapting client.js for Web Support" section below).
36
-
37
-
## Adapting client.js for Web Support
38
-
39
-
To enable web support, ensure your `client.js` file includes these modifications:
40
-
41
-
1.**Use the Browser's Native WebSocket:**
42
-
In the web version, remove or comment out any code that requires a WebSocket polyfill. For example:
43
-
```js
44
-
// const WebSocket = require('ws'); // Do not use this in the browser
45
-
```
46
-
47
-
2.**Use Global Protobuf Definitions:**
48
-
Instead of importing protobuf definitions via CommonJS, obtain them from the global scope:
35
+
-`containerPb.js` – which sets up `window.root` with your protobuf definitions
36
+
-`client.js` – the same file works in both Node.js and browser environments
37
+
- Instead of importing protobuf definitions via CommonJS, obtain them from the global scope:
0 commit comments