TronLink / tronlink-extension

TronLink Chrome Extension
2 stars 3 forks source link

window.tronWeb takes time to be set #284

Open kevholder opened 4 years ago

kevholder commented 4 years ago

Currently, the extension takes some time to load and set window.tronWeb. Is there a recommended pattern to wait for tronWeb to be set?

cuongnvicts commented 4 years ago

@kevholder Have you found any way?

cuongnvicts commented 3 years ago

@kevholder I have a workaround solution (I'm using typescript):

  const setTronWebInterval = setInterval(() => {
    this.tronWeb = (window as any)?.tronWeb;
    if (this.tronWeb) {
      clearInterval(setTronWebInterval);
    }
  }, 500);
  setTimeout(() => {
    setTronWeb && clearInterval(setTronWebInterval);
  }, 5000);