Nested Iframe doesn’t have content after reload on Mozilla

I have this problem on Mozilla (worked perfectly on Chrome) where the nested Iframe doesnt have content after reload (only empty header and body tag)

Somehow you can click on the search bar and enter (instead of reload) to open again and all iFrame will load as intended

The snippet below doesnt work on the playcode website. You should open it in localhost for it to work.
https://playcode.io/874440/

Body index.html

<body>
    <div>Index</div>
    <iframe id="iframe"></iframe>
    <script>
        (function () {
            var b = document.getElementById("iframe");
            b.setAttribute("src", "iframe.html?" + Math.random() * 100);
        })();
        window.addEventListener('beforeunload', function (event) {
            console.log('I am the 1st one.');
        });
        window.addEventListener('unload', function (event) {
            alert('unLoad')
        });
    </script>
</body>

body iframe.html

<body>
    <header>
        IFRAME1
    </header>
    <iframe id="iframe2"></iframe>
    <script>
        (function () {
            var b = document.getElementById("iframe2");
            b.setAttribute("src", "iframe2.html?" + Math.random() * 100);
        })();
        window.addEventListener('beforeunload', function (event) {
            console.log('frame 1 before unload.');
        });
        window.addEventListener('unload', function (event) {
            console.log('frame 1 unload.');
        });
        window.addEventListener('pagehide', (event) => {
            if (event.persisted === true) {
                console.log('This page *might* be entering the bfcache.');
            } else {
                console.log('This page will unload normally and be discarded.');
            }
        });
    </script>
</body>

Body iframe2.html

<body>
    <header id="h2">
        this is iframe 2
    </header>
    <script src="iframe2.js"></script>
</body>

I read something about bfcache, which is why i tried to put unload event to negate bfcache.

It seems thats not the issue.