I'm trying to leverage modules to dynamically attach variables on iframe's Window.
The problem is, that when I'm doing simple iframe.contentDocument.write(html)
, with script of type='module'
, the script inside iframe won't run.
If i use script without type='module'
, the script runs (and for example logs something to console)
Why am I unable to inject module scripts into an iframe like this? Is this some layer of security I am not aware of?
Edit:
Here is piece of code i'm injecting, i checked the network tab, and browser fetches the dependency from public directory, console.log()
doesn't run though
<script type="module">
import * as materialuicore from "/.vite/@material-ui_core.js"
console.log('materialuicore')
if (!window.__deps) window.__deps = {}
window.__deps["@material-ui/core"] = materialuicore
</script>