Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

[Bug] contexts.delete() fails with 400 — same Content-Type issue as extensions.delete() (#169)

Đang mở Phù hợp với người mới
#180 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu trong core.ts và core.mjs với logic defaultHeaders được hiển thị trong issue, sau đó so sánh logic này với request contexts.delete() và bug liên quan của extensions.delete(). Hoàn thành khi một DELETE không có body không còn nhận header Content-Type JSON và contexts.delete() hoàn tất thành công với HTTP 204 hoặc 200.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Describe the bug

bb.contexts.delete(id) fails with:

400 Body cannot be empty when content-type is set to 'application/json'

This is the same root cause as #169 (extensions.delete()). The SDK's defaultHeaders in core.ts sets Content-Type: application/json on all non-GET/HEAD methods, including DELETE — which sends no request body.

// core.mjs:140
...(['head', 'get'].includes(opts.method) ? {} : { 'Content-Type': 'application/json' }),

DELETE should be excluded here alongside get and head.

Steps to reproduce
import Browserbase from "@browserbasehq/sdk";

const bb = new Browserbase({ apiKey: process.env.BROWSERBASE_API_KEY });

// Create a context
const ctx = await bb.contexts.create({
  projectId: process.env.BROWSERBASE_PROJECT_ID,
});

// Try to delete it — fails
await bb.contexts.delete(ctx.id);
Expected behavior

Context is deleted successfully (HTTP 204 or 200).

Actual behavior

Throws BadRequestError: 400 Body cannot be empty when content-type is set to 'application/json'.

Attempting to override the header with { headers: { 'Content-Type': '' } } results in a different error: 415 Unsupported Media Type.

Workaround

Use a direct HTTP call (e.g., axios or fetch) that doesn't set Content-Type on bodyless DELETE:

import axios from "axios";

await axios.delete(
  `https://api.browserbase.com/v1/contexts/${ctx.id}`,
  { headers: { "x-bb-api-key": process.env.BROWSERBASE_API_KEY } },
);
Suggested fix

In core.ts / core.mjs, exclude delete from the Content-Type default:

...(['head', 'get', 'delete'].includes(opts.method) ? {} : { 'Content-Type': 'application/json' }),
Environment
  • @browserbasehq/sdk: latest (installed 2026-03-15)
  • Node.js: v22.21.1
  • OS: macOS (Darwin 25.2.0)
Ngôn ngữ chính
TypeScript
Star
64
Fork
17
Merge trung bình
13 phút
Pull request đã merge (30 ngày)
4

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của browserbase/sdk-node

Tất cả issue của browserbase/sdk-node

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.