There is a lot of confusion out there as to how to connect to a web3 browser using web3js, this gist shows how to connect using the most recent (2023) API updates and also providing backwards compatibilty for legacy web3 browsers.
Take a look at connect.js below
Take a look at connect.ts and global.d.ts for window.ethereum and window.web3 type definitions