This demonstrates how to cleanly detect MetaMask, MetaMask Flask, or MetaMask Institutional and connect to a Snap by using EIP-6963: Multi Injected Provider Discovery. It avoids issues caused by provider pollution when running multiple wallets in the same browser profile.
View code on GitHub