MCPcopy Index your code
hub / github.com/HtmlUnit/htmlunit / getBaseURL

Method getBaseURL

src/main/java/org/htmlunit/html/HtmlPage.java:2400–2451  ·  view source on GitHub ↗

The base URL used to resolve relative URLs. @return the base URL

()

Source from the content-addressed store, hash-verified

2398 * @return the base URL
2399 */
2400 public URL getBaseURL() {
2401 URL baseUrl;
2402 if (base_ == null) {
2403 baseUrl = getUrl();
2404 final WebWindow window = getEnclosingWindow();
2405 final boolean frame = window != null && window != window.getTopWindow();
2406 if (frame) {
2407 final boolean frameSrcIsNotSet = baseUrl == UrlUtils.URL_ABOUT_BLANK;
2408 final boolean frameSrcIsJs = "javascript".equals(baseUrl.getProtocol());
2409 if (frameSrcIsNotSet || frameSrcIsJs) {
2410 baseUrl = window.getTopWindow().getEnclosedPage().getWebResponse()
2411 .getWebRequest().getUrl();
2412 }
2413 }
2414 else if (baseUrl_ != null) {
2415 baseUrl = baseUrl_;
2416 }
2417 }
2418 else {
2419 final String href = base_.getHrefAttribute().trim();
2420 if (org.htmlunit.util.StringUtils.isEmptyOrNull(href)) {
2421 baseUrl = getUrl();
2422 }
2423 else {
2424 final URL url = getUrl();
2425 try {
2426 if (href.startsWith("http://") || href.startsWith("https://")) {
2427 baseUrl = new URL(href);
2428 }
2429 else if (href.startsWith("//")) {
2430 baseUrl = new URL("%s:%s".formatted(url.getProtocol(), href));
2431 }
2432 else if (href.length() > 0 && href.charAt(0) == '/') {
2433 final int port = Window.getPort(url);
2434 baseUrl = new URL("%s://%s:%d%s".formatted(url.getProtocol(), url.getHost(), port, href));
2435 }
2436 else if (url.toString().endsWith("/")) {
2437 baseUrl = new URL("%s%s".formatted(url, href));
2438 }
2439 else {
2440 baseUrl = new URL(UrlUtils.resolveUrl(url, href));
2441 }
2442 }
2443 catch (final MalformedURLException e) {
2444 notifyIncorrectness("Invalid base url: \"" + href + "\", ignoring it");
2445 baseUrl = url;
2446 }
2447 }
2448 }
2449
2450 return baseUrl;
2451 }
2452
2453 /**
2454 * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>

Callers 7

baseURI_noBaseTagMethod · 0.95
getBaseUrlMethod · 0.95
getFullyQualifiedUrlMethod · 0.95
getBaseURIMethod · 0.80

Calls 15

getTopWindowMethod · 0.95
getProtocolMethod · 0.95
getPortMethod · 0.95
getHostMethod · 0.95
resolveUrlMethod · 0.95
trimMethod · 0.80
endsWithMethod · 0.80
notifyIncorrectnessMethod · 0.80
getUrlMethod · 0.65
getEnclosingWindowMethod · 0.65
getWebResponseMethod · 0.65
getEnclosedPageMethod · 0.65

Tested by 5

baseURI_noBaseTagMethod · 0.76
getBaseUrlMethod · 0.76