-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
Summary
The CDP method Network.getResponseBody returns raw bytes directly in the response body, but the CDP protocol specification requires binary content to be base64 encoded when base64Encoded is false or for non-text responses.
Steps to Reproduce
- Start Lightpanda browser
- Navigate to a page that returns binary content (e.g., an image)
- Use CDP to call
Network.getResponseBodyon the image request - Observe that raw bytes are returned instead of base64 encoded content
Expected Behavior
According to CDP protocol spec, Network.getResponseBody should:
- Return base64 encoded content when
base64Encoded: true - Return string content for text responses
- Handle binary content appropriately
Actual Behavior
In src/cdp/domains/network.zig:204-215, the function returns raw bytes:
try cmd.sendResult(.{
.body = buf.items,
.base64Encoded = false,
}, .{});Root Cause Analysis
Location: src/cdp/domains/network.zig:204-215
The code directly returns buf.items (raw bytes) with base64Encoded: false. This violates the CDP specification when:
- The response is binary (image, video, etc.)
- The content contains non-UTF8 bytes
The CDP protocol states that for binary content, the server should either:
- Return base64 encoded string with
base64Encoded: true - Or ensure the content is valid UTF-8 text
Additionally, there's no Content-Type check to determine if the response is binary or text.
Proposed Solution
- Check the Content-Type header to determine if response is binary
- If binary, encode to base64 and set
base64Encoded: true - If text, ensure proper UTF-8 encoding before returning
- Add MIME type checking (images, videos, etc. should always be base64)
Code Reference
fn getResponseBody(cmd: anytype) !void {
// ... existing code ...
// Add MIME type check
const mime = rh.contentType() orelse "application/octet-stream";
const is_binary = isBinaryMimeType(mime);
if (is_binary) {
// Base64 encode the binary content
const encoded = try base64Encode(buf.items, arena);
return cmd.sendResult(.{ .body = encoded, .base64Encoded = true }, .{});
}
return cmd.sendResult(.{ .body = buf.items, .base64Encoded = false }, .{});
}Environment
- OS: Linux
- Version: Lightpanda latest
- Zig: latest
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels