Do web browsers use separate executional threads for JavaScript in iframes?
I believe Chrome uses separate threads for each tab, so I am guessing that JavaScript in an iframe would share the same thread as its parent window, however, that seems like a security risk too.
As long as the protocol, domain and port of the parent page and iframe match, everything will work fine.
Iframes Bring Security Risks. If you create an iframe, your site becomes vulnerable to cross-site attacks. You may get a submittable malicious web form, phishing your users' personal data. A malicious user can run a plug-in.
Browsers aren't single threaded, but your script runs in a single runloop.
The iframe element is supported by all modern desktop and mobile browsers.
Recently tested if JavaScript running in a iFrame would block JavaScript from running in the parent window.
iFrame on same domain as parent:
iFrame on different domain as parent
chrome://process-internals
and chrome://flags
)parent.html:
<body> <div id="count"></div> <iframe src="./spin.html"></iframe> <script> let i = 0; let div = document.getElementById("count"); setInterval(() => { div.innerText = i++; }, 100); </script> </body>
spin.html:
<body> <button id="spin">spin</button> <script> const spin = document.getElementById("spin"); spin.addEventListener('click', () => { const start = Date.now(); while (Date.now() - start < 1000) { } }) </script> </body>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With