document.URL and the other approaches you’re using will fail because Observable notebooks run in an iframe.
I don’t see an easy way to read the URL of the containing page since that is likely to go against the same-origin policy. E.g. Actually, see below!
SecurityError: Permission denied to get property "href" on cross-origin object.
Edit: Oh, I just realized that you said you only want the
location.hash. If you’re planning to parse that info and use it as user-provided data in your notebook, an alternate approach is to use the query parameters (stuff after
? in the URL) as shown in these notebooks:
EDIT 2: Hmm, the notebooks above provide a solution to part of the original question:
document.baseURI will return the URL of the containing page, but unfortunately it does not seem to contain the URL hash…