There is a lot of confusion out there as to how to connect to a web3 browser using web3js, the linked gist shows how to connect using the most recent (2023) API updates and also providing backwards compatibilty for legacy web3 browsers.
Checkout the linked gist here