MCPcopy Create free account
hub / github.com/ChromeDevTools/chrome-devtools-mcp / resolveScriptSource

Function resolveScriptSource

src/tools/script.ts:219–246  ·  view source on GitHub ↗
(
  inlineSource: string | undefined,
  sourcePath: string | undefined,
  context: Context,
)

Source from the content-addressed store, hash-verified

217);
218
219const resolveScriptSource = async (
220 inlineSource: string | undefined,
221 sourcePath: string | undefined,
222 context: Context,
223): Promise<string> => {
224 if (inlineSource !== undefined) {
225 if (sourcePath !== undefined) {
226 throw new Error('Specify exactly one of function or sourcePath.');
227 }
228 return inlineSource;
229 }
230 if (sourcePath === undefined) {
231 throw new Error('Specify exactly one of function or sourcePath.');
232 }
233
234 const resourceUrl = sourcePath.startsWith('file:')
235 ? sourcePath
236 : pathToFileURL(sourcePath).href;
237 try {
238 return await context.loadResource(resourceUrl);
239 } catch (error) {
240 const errorMessage = error instanceof Error ? error.message : String(error);
241 throw new Error(
242 `Unable to read script source from ${sourcePath}: ${errorMessage}`,
243 {cause: error},
244 );
245 }
246};
247
248const performEvaluation = async (
249 evaluatable: Evaluatable,

Callers 1

script.tsFile · 0.85

Calls 1

loadResourceMethod · 0.80

Tested by

no test coverage detected