Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/perky-hands-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lit-protocol/lit-client': patch
---

Browser apps can now enable raw Lit node HTTP response logging by setting window.DEBUG_HTTP='true' before loading the SDK
1 change: 1 addition & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
{
"group": "Resources",
"pages": [
"sdk/resources/debug-logging",
"sdk/resources/supported-evm-chains",
"sdk/resources/network-status"
]
Expand Down
57 changes: 57 additions & 0 deletions docs/sdk/resources/debug-logging.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: "Debug Logging"
description: "Enable Lit JS SDK debug logging in browsers and Node.js."
---

# Overview

Use SDK logs to inspect Lit Action requests and responses. Logging is disabled by default.
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation inconsistently refers to inspecting "Lit Action requests and responses" in the Overview section (line 8), but the DEBUG_HTTP flag is actually for logging HTTP responses from Lit node requests in general, not specifically Lit Actions. Consider revising this to be more accurate, such as "Use SDK logs to inspect Lit node requests and responses" or "Use SDK logs to inspect network communication with Lit nodes."

Suggested change
Use SDK logs to inspect Lit Action requests and responses. Logging is disabled by default.
Use SDK logs to inspect Lit node requests and responses. Logging is disabled by default.

Copilot uses AI. Check for mistakes.

## Browser

Set `window.LOG_LEVEL` before the SDK bundle loads (or before your first `@lit-protocol/*` import). The logger is initialized at module load time, so setting it afterward will not take effect.

```html
<script>
window.LOG_LEVEL = 'debug';
</script>
<script type="module" src="/src/main.tsx"></script>
```

If your entrypoint is a module, set the flag before a dynamic import:

```ts
window.LOG_LEVEL = 'debug';
const { createLitClient } = await import('@lit-protocol/lit-client');
```

## Node.js

Set `LOG_LEVEL=debug` (or `info`) before running the app:

```bash
LOG_LEVEL=debug node app.js
```

## HTTP Response Logging

Set `DEBUG_HTTP=true` to log raw HTTP responses and a generated `curl` command for each node request.

```bash
LOG_LEVEL=debug DEBUG_HTTP=true node app.js
```

In browsers, set the flag on `window` before the SDK loads:

```html
<script>
window.DEBUG_HTTP = 'true';
window.LOG_LEVEL = 'debug';
</script>
```

## What You Can and Cannot See

- The SDK does not surface decrypted per-node payloads in browser logs.
- `executeJs` returns `result.response` and `result.logs` (aggregated console output from your Lit Action).
- To inspect decrypted data, explicitly log or return it from the Lit Action (be careful with secrets).
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ function generateCurlCommand(url: string, req: any): string {
return `curl -X ${req.method} ${headers} ${body} "${url}"`.trim();
}

const isDebugHttpEnabled = (): boolean => {
try {
if (
typeof process !== 'undefined' &&
typeof process.env === 'object' &&
process.env['DEBUG_HTTP'] === 'true'
) {
return true;
}
} catch (e) {
// Ignore any errors - ensures browser compatibility
}

try {
const debugHttp = (globalThis as any).DEBUG_HTTP;
return debugHttp === true || debugHttp === 'true';
} catch (e) {
// Ignore any errors - ensures browser compatibility
}

return false;
};

export async function sendNodeRequest<T>(
// Interface for common request parameters
params: {
Expand Down Expand Up @@ -71,17 +94,7 @@ export async function sendNodeRequest<T>(
const response = await fetch(_fullUrl, req);

// Only log response details when DEBUG_HTTP is enabled
// Safely check for DEBUG_HTTP environment variable in both Node.js and browser
let isDebugMode = false;
try {
isDebugMode =
typeof process !== 'undefined' &&
typeof process.env === 'object' &&
process.env['DEBUG_HTTP'] === 'true';
} catch (e) {
// Ignore any errors - ensures browser compatibility
isDebugMode = false;
}
const isDebugMode = isDebugHttpEnabled();

if (isDebugMode) {
const timestamp = new Date().toISOString();
Expand Down
Loading