MCPcopy Create free account
hub / github.com/ChromeDevTools/devtools-frontend / fetchFileAsText

Function fetchFileAsText

front_end/testing/TraceLoader.ts:290–309  ·  view source on GitHub ↗
(url: URL)

Source from the content-addressed store, hash-verified

288}
289
290export async function fetchFileAsText(url: URL): Promise<string> {
291 if (typeof window === 'undefined') {
292 // @ts-expect-error no node types here.
293 const fs = await import('node:fs/promises');
294 // @ts-expect-error no node types here.
295 const {fileURLToPath} = await import('node:url');
296 const path = fileURLToPath(url);
297 const buffer = await fs.readFile(path);
298 const contents = await Common.Gzip.arrayBufferToString(buffer);
299 return contents;
300 }
301 const response = await fetch(url);
302 if (response.status !== 200) {
303 throw new Error(`Unable to load ${url}`);
304 }
305
306 const buffer = await response.arrayBuffer();
307 const contents = await Common.Gzip.arrayBufferToString(buffer);
308 return contents;
309}
310
311// Below this point are private methods used in the TraceLoader class. These
312// are purposefully not exported, you should use one of the static methods

Callers 2

loadScriptFixtureFunction · 0.85
loadTraceFileFromURLMethod · 0.85

Calls 2

fetchFunction · 0.85
readFileMethod · 0.80

Tested by 1

loadScriptFixtureFunction · 0.68