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

Function resolveScriptSource

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

Source from the content-addressed store, hash-verified

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

Callers 1

script.tsFile · 0.85

Calls 1

loadResourceMethod · 0.80

Tested by

no test coverage detected