Skip to content

Commit acb2943

Browse files
authored
Merge pull request #402 from convertcom/main-convert
Main convert
2 parents 34f0a7a + 095b70f commit acb2943

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

packages/utils/src/http-client.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ const determineRuntime = (): RuntimeResult => {
137137
return {runtime: 'browser'};
138138
}
139139

140+
// Browser Web Workers have no `window` but are still browser runtimes.
141+
// `importScripts` exists only in browser worker scopes — server runtimes
142+
// (Node.js) and edge runtimes (e.g. Cloudflare Workers) do not expose it.
143+
// Without this check a Web Worker falls through to 'server-with-fetch' and
144+
// server-side-only behavior leaks into real browsers (the ConvertAgent
145+
// User-Agent announcement below forced a CORS preflight the signals
146+
// endpoint rejected, breaking every signals worker upload).
147+
if (
148+
typeof self !== 'undefined' &&
149+
typeof (self as {importScripts?: unknown})?.importScripts === 'function'
150+
) {
151+
return {runtime: 'browser'};
152+
}
153+
140154
// if window is not available, but fetch is, then we're on a server that has the fetch API available
141155
if (typeof fetch === 'function') {
142156
return {runtime: 'server-with-fetch'};

0 commit comments

Comments
 (0)