'Metamask mobile browser not injecting window.ethereum

I'm having an issue where Metamask's mobile browser simply isn't injecting window.ethereum at all into my website. This is extra confusing since I'm doing everything the same way I did in a previous website that worked fine.

        if (window.ethereum) {
            this.handleEthereum();
        } else {
            window.addEventListener('ethereum#initialized', this.handleEthereum, {
                once: true,
            });
        }

To confirm that window.ethereum is never injected I also just output it on the screen and it's stays undefined indefinitely.

Everything works completely fine using a desktop browser of course. It's only an issue with metamask's mobile browser.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source