diff --git a/extensions/slack/src/monitor/media.ts b/extensions/slack/src/monitor/media.ts index 79df40ec2cb..769d36117a2 100644 --- a/extensions/slack/src/monitor/media.ts +++ b/extensions/slack/src/monitor/media.ts @@ -95,6 +95,10 @@ function createSlackMediaFetch(): FetchLike { }; } +function resolveSlackFetchForRuntime(): typeof fetch { + return isMockedFetch(globalThis.fetch) ? globalThis.fetch : fetchWithRuntimeDispatcher; +} + /** * Fetches a URL with Authorization header while keeping same-origin redirects * authenticated and dropping auth once the redirect crosses origins. @@ -102,8 +106,9 @@ function createSlackMediaFetch(): FetchLike { export async function fetchWithSlackAuth(url: string, token: string): Promise { const parsed = assertSlackFileUrl(url); const authHeaders = createSlackAuthHeaders(token); + const fetchImpl = resolveSlackFetchForRuntime(); - const initialRes = await fetch(parsed.href, { + const initialRes = await fetchImpl(parsed.href, { headers: authHeaders, redirect: "manual", }); @@ -122,12 +127,12 @@ export async function fetchWithSlackAuth(url: string, token: string): Promise