diff --git a/.changeset/quick-lies-pull.md b/.changeset/quick-lies-pull.md new file mode 100644 index 0000000..7dbf8e9 --- /dev/null +++ b/.changeset/quick-lies-pull.md @@ -0,0 +1,5 @@ +--- +'@hono/vite-dev-server': patch +--- + +fix: set `navigator.userAgent` correctly diff --git a/packages/dev-server/src/adapter/cloudflare.ts b/packages/dev-server/src/adapter/cloudflare.ts index f7fcdec..6a4892f 100644 --- a/packages/dev-server/src/adapter/cloudflare.ts +++ b/packages/dev-server/src/adapter/cloudflare.ts @@ -16,11 +16,18 @@ export const cloudflareAdapter: (options?: CloudflareAdapterOptions) => Promise< proxy ??= await getPlatformProxy(options?.proxy) // Cache API provided by `getPlatformProxy` currently do nothing. Object.assign(globalThis, { caches: proxy.caches }) - Object.assign(globalThis, { - navigator: { + if (typeof globalThis.navigator === 'undefined') { + // @ts-expect-error not typed well + globalThis.navigator = { userAgent: 'Cloudflare-Workers', - }, - }) + } + } else { + Object.defineProperty(globalThis.navigator, 'userAgent', { + value: 'Cloudflare-Workers', + writable: false, + }) + } + return { env: proxy.env, executionContext: proxy.ctx,