I have a JS web component that needs to load in other resources (specifically a src for an iframe it adds to the DOM, but this would be a problem for any resource with a relative path).
This resource needs to be specified relative to the calling page, which I can get easily enough from window.location.
However, the file that it needs to point the src at is relative to the JS file that's executing, and as that's a component I can't be sure where it will be.
So:
example.com/index.html
|__> {unknown path}/web-component.js
|__> {unknown path}/resource.html <-- I want to get this
That component might be in node_modules or bower_components or webpackOutput or wherever, but the DOM it creates needs to point to the same location that it has been served from, not the page that's executing it.
As this code is in a web component document.currentScript is null and document.getElementsByTagName('script') might not include the component.