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

Method completeURL

front_end/core/common/ParsedURL.ts:332–391  ·  view source on GitHub ↗
(baseURL: Platform.DevToolsPath.UrlString, href: string)

Source from the content-addressed store, hash-verified

330 }
331
332 static completeURL(baseURL: Platform.DevToolsPath.UrlString, href: string): Platform.DevToolsPath.UrlString|null {
333 // Return special URLs as-is.
334 if (href.startsWith('data:') || href.startsWith('blob:') || href.startsWith('javascript:') ||
335 href.startsWith('mailto:')) {
336 return href as Platform.DevToolsPath.UrlString;
337 }
338
339 // Return absolute URLs with normalized path and other components as-is.
340 const trimmedHref = href.trim();
341 const parsedHref = this.fromString(trimmedHref);
342 if (parsedHref?.scheme) {
343 const securityOrigin = parsedHref.securityOrigin();
344 const pathText = normalizePath(parsedHref.path);
345 const queryText = parsedHref.queryParams && `?${parsedHref.queryParams}`;
346 const fragmentText = parsedHref.fragment && `#${parsedHref.fragment}`;
347 return securityOrigin + pathText + queryText + fragmentText as Platform.DevToolsPath.UrlString;
348 }
349
350 const parsedURL = this.fromString(baseURL);
351 if (!parsedURL) {
352 return null;
353 }
354
355 if (parsedURL.isDataURL()) {
356 return href as Platform.DevToolsPath.UrlString;
357 }
358
359 if (href.length > 1 && href.charAt(0) === '/' && href.charAt(1) === '/') {
360 // href starts with "//" which is a full URL with the protocol dropped (use the baseURL protocol).
361 return parsedURL.scheme + ':' + href as Platform.DevToolsPath.UrlString;
362 }
363
364 const securityOrigin = parsedURL.securityOrigin();
365 const pathText = parsedURL.path;
366 const queryText = parsedURL.queryParams ? '?' + parsedURL.queryParams : '';
367
368 // Empty href resolves to a URL without fragment.
369 if (!href.length) {
370 return securityOrigin + pathText + queryText as Platform.DevToolsPath.UrlString;
371 }
372
373 if (href.charAt(0) === '#') {
374 return securityOrigin + pathText + queryText + href as Platform.DevToolsPath.UrlString;
375 }
376
377 if (href.charAt(0) === '?') {
378 return securityOrigin + pathText + href as Platform.DevToolsPath.UrlString;
379 }
380
381 const hrefMatches = href.match(/^[^#?]*/);
382 if (!hrefMatches || !href.length) {
383 throw new Error('Invalid href');
384 }
385 let hrefPath: string = hrefMatches[0];
386 const hrefSuffix = href.substring(hrefPath.length);
387 if (hrefPath.charAt(0) !== '/') {
388 hrefPath = parsedURL.folderPathComponents + '/' + hrefPath;
389 }

Callers 13

parseSourcesMethod · 0.45
attachSourceMapMethod · 0.45
resolveURLMethod · 0.45
ParsedURL.test.tsFile · 0.45
getSourceMapResourceMethod · 0.45
processImageResourceMethod · 0.45
processShortcutsMethod · 0.45
processPresentationMethod · 0.45

Calls 7

fromStringMethod · 0.95
normalizePathFunction · 0.85
trimMethod · 0.80
isDataURLMethod · 0.80
substringMethod · 0.80
securityOriginMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected