MCPcopy
hub / github.com/darkreader/darkreader / getOKResponse

Function getOKResponse

src/utils/network.ts:3–28  ·  view source on GitHub ↗
(url: string, mimeType?: string, origin?: string)

Source from the content-addressed store, hash-verified

1import {isFirefox} from './platform';
2
3async function getOKResponse(url: string, mimeType?: string, origin?: string): Promise<Response> {
4 const credentials = origin && url.startsWith(`${origin}/`) ? undefined : 'omit';
5 const response = await fetch(
6 url,
7 {
8 cache: 'force-cache',
9 credentials,
10 referrer: origin,
11 },
12 );
13
14 // Firefox bug, content type is "application/x-unknown-content-type"
15 if (isFirefox && mimeType === 'text/css' && url.startsWith('moz-extension://') && url.endsWith('.css')) {
16 return response;
17 }
18
19 if (mimeType && !(response.headers.get('Content-Type') === mimeType || response.headers.get('Content-Type')!.startsWith(`${mimeType};`))) {
20 throw new Error(`Mime type mismatch when loading ${url}`);
21 }
22
23 if (!response.ok) {
24 throw new Error(`Unable to load ${url} ${response.status} ${response.statusText}`);
25 }
26
27 return response;
28}
29
30export async function loadAsDataURL(url: string, mimeType?: string): Promise<string> {
31 const response = await getOKResponse(url, mimeType);

Callers 3

loadAsDataURLFunction · 0.85
loadAsBlobFunction · 0.85
loadAsTextFunction · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected