Skip to content

Commit eede997

Browse files
committed
fix(browser): prevent fetch proxy fallback
1 parent 6d58116 commit eede997

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

packages/bcode-browser/src/fetch-use.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// FetchUse — Effect service that proxies HTTP through Browser Use's fetch-use
22
// cloud (Chrome JA4, HTTP/2 header order, session cookies). Decisions §3.3.
3-
// `enabled` is true when either a direct Browser Use API key or a scoped proxy
4-
// token is set; webfetch.ts combines this with the user's
5-
// `experimental.fetch_use` opencode.json setting.
3+
// `enabled` selects this route when direct credentials are complete or any
4+
// scoped-proxy setting is present. Partial proxy config stays selected and
5+
// errors instead of silently falling back to native HTTP.
66

77
import { Context, Effect, Layer } from "effect"
88
import { HttpClient, HttpClientRequest } from "effect/unstable/http"
@@ -37,7 +37,7 @@ export const makeLayer = (options: { proxyUrl: string; apiKey: string; proxyToke
3737
const proxyEnabled = options.proxyUrl.length > 0 && options.proxyToken.length > 0
3838
const directEnabled = !hasProxySetting && options.apiKey.length > 0
3939
return Service.of({
40-
enabled: proxyEnabled || directEnabled,
40+
enabled: hasProxySetting || directEnabled,
4141
fetch: (url, { timeoutMs }) =>
4242
Effect.gen(function* () {
4343
if (!proxyEnabled && !directEnabled) {

packages/bcode-browser/test/fetch-use.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ import { FetchHttpClient } from "effect/unstable/http"
1212
import { FetchUse } from "../src/fetch-use"
1313

1414
const haveProxySetting = !!process.env.BROWSER_USE_FETCH_URL || !!process.env.BROWSER_USE_FETCH_TOKEN
15-
const haveCredential =
16-
(!!process.env.BROWSER_USE_FETCH_URL && !!process.env.BROWSER_USE_FETCH_TOKEN) ||
17-
(!haveProxySetting && !!process.env.BROWSER_USE_API_KEY)
15+
const fetchUseSelected = haveProxySetting || !!process.env.BROWSER_USE_API_KEY
1816

19-
test("layer constructs and exposes `enabled` reflecting env", async () => {
17+
test("layer selects fetch-use for direct or scoped-proxy configuration", async () => {
2018
const enabled = await Effect.gen(function* () {
2119
return (yield* FetchUse.Service).enabled
2220
}).pipe(Effect.provide(FetchUse.layer.pipe(Layer.provide(FetchHttpClient.layer))), Effect.runPromise)
23-
expect(enabled).toBe(haveCredential)
21+
expect(enabled).toBe(fetchUseSelected)
2422
})
2523

2624
test.skipIf(!process.env.BROWSER_USE_API_KEY)("live: fetches httpbin and returns body + content-type", async () => {
@@ -79,7 +77,8 @@ test.each([
7977
])("partial proxy configuration fails closed", async (options) => {
8078
const result = await Effect.gen(function* () {
8179
const service = yield* FetchUse.Service
82-
expect(service.enabled).toBe(false)
80+
// Keep this route selected so webfetch cannot silently use native HTTP.
81+
expect(service.enabled).toBe(true)
8382
return yield* Effect.flip(service.fetch("https://example.com", { timeoutMs: 1_000 }))
8483
}).pipe(
8584
Effect.provide(FetchUse.makeLayer(options).pipe(Layer.provide(FetchHttpClient.layer))),

0 commit comments

Comments
 (0)