# Browser crash on tab close... why?

**URL:** <https://discourse.threejs.org/t/browser-crash-on-tab-close-why/78834>\
**Category:** Questions\
**Created:** [March 1, 2025, 7:22pm UTC](https://discourse.threejs.org/t/browser-crash-on-tab-close-why/78834 "2025-03-01T19:22:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bandinopla](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/bandinopla/32/56250_2.png) [@bandinopla](https://discourse.threejs.org/u/bandinopla)\
**Post date:** [March 1, 2025, 7:22pm UTC](https://discourse.threejs.org/t/browser-crash-on-tab-close-why/78834/1 "2025-03-01T19:22:53Z")

</div>

I have a scene that loads relatively fine on an old laptop, but when I close the browser tab it freezes and hangs. I am forced to terminate the browser… What is the reason for this?

I have this which I thought would help but it doesn’t:

```js
        window.addEventListener('beforeunload', () => {
            this.renderer.setAnimationLoop(null);
            this.traverse((obj) => {
                if( obj instanceof THREE.Mesh )
                {
                    if (obj.geometry) obj.geometry.dispose();
                    if (obj.material) {
                        if (obj.material.map) obj.material.map.dispose();
                        obj.material.dispose();
                    }
                } 
                
            });

            this.composer.passes.forEach(pass => {
                if (pass instanceof ShaderPass) {
                    pass.material.dispose();
                    //@ts-ignore
                    if (pass.fsQuad) pass.fsQuad.geometry.dispose();
                }
            });
            this.composer.renderTarget1.dispose();
            this.composer.renderTarget2.dispose();
            this.composer.dispose();

            this.renderer.dispose();
            this.renderer.forceContextLoss();
        });

```

---

<div class="post-metadata">

**Author:** ![Fennec](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fennec/32/59265_2.png) [@Fennec](https://discourse.threejs.org/u/Fennec)\
**Post date:** [March 1, 2025, 7:39pm UTC](https://discourse.threejs.org/t/browser-crash-on-tab-close-why/78834/2 "2025-03-01T19:39:30Z")

</div>

When you close the tab, the browser will automatically dispose of everything. No manual cleanup needed!

---

<div class="post-metadata">

**Author:** ![bandinopla](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/bandinopla/32/56250_2.png) [@bandinopla](https://discourse.threejs.org/u/bandinopla)\
**Post date:** [March 1, 2025, 7:53pm UTC](https://discourse.threejs.org/t/browser-crash-on-tab-close-why/78834/3 "2025-03-01T19:53:33Z")

</div>

yeah I thought about that, but why could it be that it crashes? I tested the examples page of threejs in this laptop and they run fine… but my app makes it crash on tab close… so it is clearly some optimization problem on my side…

---

<div class="post-metadata">

**Author:** ![Fennec](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fennec/32/59265_2.png) [@Fennec](https://discourse.threejs.org/u/Fennec)\
**Post date:** [March 1, 2025, 8:15pm UTC](https://discourse.threejs.org/t/browser-crash-on-tab-close-why/78834/4 "2025-03-01T20:15:28Z")

</div>

It depends on your scene, if you have lots of objects, that could be the cause.

I’ve used this kind of cleanup in `dev` mode with `vue`, as it tends to reload the entire `Scene` on top of existing resources with every edit, it generally worked well!

Try removing blocks (`setAnimationLoop`, `traverse`, `composer`…), and test which block is causing the problem. Isolating the issue this way can help narrow down the root cause!

---

<div class="post-metadata">

**Author:** ![bandinopla](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/bandinopla/32/56250_2.png) [@bandinopla](https://discourse.threejs.org/u/bandinopla)\
**Post date:** [March 1, 2025, 9:02pm UTC](https://discourse.threejs.org/t/browser-crash-on-tab-close-why/78834/5 "2025-03-01T21:02:44Z")

</div>

Do you know if there’s an industry standard or something on what is a good or acceptable size for a threejs app? Or how much memory should it use? Are there well known baselines that people that has been doing this for a while have somewhat established? I’m asking to see if maybe I’m going well beyond what it is common knowledge and I’m being ignorant about.

---

<div class="post-metadata">

**Author:** ![kpachinger](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/kpachinger/32/4616_2.png) [@kpachinger](https://discourse.threejs.org/u/kpachinger)\
**Post date:** [March 1, 2025, 9:03pm UTC](https://discourse.threejs.org/t/browser-crash-on-tab-close-why/78834/6 "2025-03-01T21:03:34Z")

</div>

My former operation (PEMDAS) stated that `onBeforeUnload` was inherently disreputable. Ad trackers often bundle a final salvo… which can be more confusing than `onPageLoad` since you are gone. You might inspect `sources` of other scripts that add listeners… set them to null.

I never set a recursive loop after I left.

---

<div class="post-metadata">

**Author:** ![Fennec](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fennec/32/59265_2.png) [@Fennec](https://discourse.threejs.org/u/Fennec)\
**Post date:** [March 1, 2025, 9:35pm UTC](https://discourse.threejs.org/t/browser-crash-on-tab-close-why/78834/7 "2025-03-01T21:35:43Z")

</div>

Generally speaking, you want your app to run on as many devices as possible. This means testing it on low-end desktops and mobile devices, you’ll eventually need to make some trade-offs. unless it’s a niche market you’ll have to test it on the targeted devices.

In Chrome, the **Performance** tab allows you to throttle the CPU and emulate low-end devices. there are also online services provide performance and responsiveness evaluations for multiple devices.

---

<div class="post-metadata">

**Author:** ![manthrax](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/manthrax/32/2596_2.png) [@manthrax](https://discourse.threejs.org/u/manthrax)\
**Post date:** [March 2, 2025, 1:22am UTC](https://discourse.threejs.org/t/browser-crash-on-tab-close-why/78834/8 "2025-03-02T01:22:15Z")

</div>

I have never seen that behavior, but I only run Chrome.

Which browser is this happening in? Do you have any browser extensions running?

---

<div class="post-metadata">

**Author:** ![bandinopla](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/bandinopla/32/56250_2.png) [@bandinopla](https://discourse.threejs.org/u/bandinopla)\
**Post date:** [March 2, 2025, 7:27am UTC](https://discourse.threejs.org/t/browser-crash-on-tab-close-why/78834/9 "2025-03-02T07:27:12Z")

</div>

tested on chrome and brave. No extensions. Tested on a plain office laptop…
