title: Get URL of current module script
body: <p>I haven't found any mentions in the <a href="https://www.w3.org/TR/html52/" rel="noreferrer">HTML spec</a> nor anywhere on the web, that says this is possible, still I ask just in case.</p>
  
  <p>Is it possible to get the URL of a module to for example fetch files relative to that URL? </p>
  
  <p>Let's say my <code>index.html</code> has a:</p>
  
  <pre><code>&lt;script type="module"&gt;import '/foo/foo.js'&lt;/script&gt;
  </code></pre>
  
  <p>and <code>foo.js</code> wants to know what it's own url is to load dynamically some file e.g. <code>./file-inside-foo</code>. </p>
  
  <p>As of the time of this writing <code>document.currentScript</code> returns <code>null</code> inside modules and is probably like that by design?</p>