I use svelte to create Web3 app and got some error
1.I already added web3.js cdn on my index.html
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
2.this is my script on .svelte file to connect the Metamask Wallet
function connectWallet(){
if(window.ethereum){
window.web3 = new Web3(ethereum);
window.ethereum.enable();
metamaskConnected = window.ethereum.isConnected();
web3.eth.getAccounts(function(error, accounts) {
WalletAddress = accounts
console.log(error)
})
}
}
And when i open my website on the broser (Brave) for the first time i got this error
Unchecked runtime.lastError: Could not establish connection
and the script not working
- I have to refresh my page and then the error disappear so my code works normally
Could you give me some suggestion, Thank you very much