Everything I can think of is hacky, but the basic idea is:
Have a javascript snippet assign the value of window.location.search to a hidden input (styled with display: none) using jQuery. Input is guaranteed to have a stable id, check developer console.
Use changeSubmit javascript function to save the value. Make sure you generate the javascript bit with changeSubmit only once, otherwise it will keep submitting.
In page building code, update some state variable with input's value if there is one.
If that last part of the URL is coming from your own app, you could also consider some way to save that (e.g., in state) since you'd probably know what it is/where it's coming from in that case. If this is URL is being hit from another app (or driver or hub/system entirely...), then OAuth with an endpoint is probably a better idea than banging directly against this hub URL--and in those cases you normally don't need to worry about URLs at all besides the one the API can provide for you and the ones you "map" in your app. Something else to consider, depending on what's really happening.
Does it need to be HTML? Can you just use an href() instead of a paragraph() or whatever you're using now? You can pass parameters to that. Just another idea.
Yeah, an href would definitely be a gray box. (It's probably adjustable with styles, but I'm not sure I'd want to mess with that.) Parameters are an optional Map argument called params that can passed. Not sure there's any great examples, but here's one: Passing parameter with href
paragraph "<p id=\"demo\"></p><script>document.getElementById(\"demo\").innerHTML = \"The full URL of this page is:<br>\" + window.location.href;</script>"
Use atomicState.tpu instead. That should solve it, at least did for me in one of my apps. That forces a trip to the database to get value back trying to get it from memory.
When you assign that value to state.thePageURL, you are literally assigning that HTML code as text to the variable. There's no return value.
My guess is that when you try to display it later, the Hubitat page is rendering it in place. So, it seems like you're seeing a stored value, but it is really just the HTML being rendered into the page at that point. I'm not sure why it only runs once, though
I think you need to find a way to render it programmatically and scrape the result, ideally without displaying it.
I'm not sure what the appropriate contentType would be. You may have to try various, depending on how much code you want there and what Hubitat supports in render() Maybe "application/javascript" or others: HTTP headers | Content-Type - GeeksforGeeks
In the next iteration, we'll have a setting name hubitatQueryString, populated when a page is opened. Then you can parse the JSON out of it. Just chill for a little while