An injected wallet exposes `window.ethereum` with `request({ method, params })` and events such as `accountsChanged` and `chainChanged`. Requesting accounts triggers the connect prompt.
const [account] = await window.ethereum.request({ method: "eth_requestAccounts" });
window.ethereum.on("chainChanged", () => location.reload());Never auto-connect on page load without user intent, and always re-read the chain id before a write.