How do I get the current URL of my application?

I need the URL of my current application because I need to generate a link to another component of my website which is located on a subpath of my URL (e.g. the VAADIN application is under http://localhost:8080 and the other component is under http://localhost:8080/widget/?someCode=1

I want to provide the option to copy the URL to clipboard so you can paste it to OBS. How do I programatically get the “http://localhost:8080/” portion of that URL?

Solved by delegating the URL fetching to javascript with windows.location.href

There is a method on the page:

UI.getCurrent().getPage().fetchCurrentURL(url -> {
     // do something with it     
});

yes I tried that but it didn’t return anything but an empty string

though handling that in JavaScript now is actually the better approach as I’m calling JavaScript afterwards anyways to put the found url into clipboard. So I just altered that functionality to also fetch the url and do the splicing

If you do not need the URL on the server that sounds like a better approach. Pretty close to this one? https://cookbook.vaadin.com/copy-to-clipboard

yes exactly that one. copied the snippet from there and then prepend the given string with the URL I get from windows.location.href