Skip to content

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

@sashank-zluri

Description

@sashank-zluri

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions