Tuesday, October 3, 2023
HomeSoftware DevelopmentThe right way to Detect Failed Requests by way of Internet Extensions

The right way to Detect Failed Requests by way of Internet Extensions


Top-of-the-line issues that ever occurred to t he consumer expertise of the online has been internet extensions. Browsers are highly effective however extensions deliver a brand new degree of performance. Whether or not it is crypto wallets, media gamers, or different common plugins, internet extensions have develop into important to daily duties.

Engaged on MetaMask, I’m thrust right into a world of constructing every part Ethereum-centric work. A type of functionalities is guaranteeing that .eth domains resolve to ENS when enter to the handle bar. Requests to https://vitalik.ethnaturally fail, since .eth is not a natively supported prime degree area, so we have to intercept this errant request.

// Add an onErrorOccurred occasion by way of the browser.webRequest extension API
browser.webRequest.onErrorOccurred.addListener((particulars) => {
  const { tabId, url } = particulars;
  const { hostname } = new URL(url);

  if(hostname.endsWith('.eth')) {
    // Redirect to wherever I would like the consumer to go
    browser.tabs.replace(tabId, { url: `https://app.ens.domains/${hostname}}` });
  }
},
{
  urls:[`*://*.eth/*`],
  varieties: ['main_frame'],
});

Internet extensions present a browser.webRequest.onErrorOccurred methodology that builders can plug into to hear for errant requests. This API does not catch 4** and 5** response errors. Within the case above, we search for .eth hostnames and redirect to ENS.

You possibly can make use of onErrorOccurred for any variety of causes, however detecting customized hostnames is a good one!



Supply hyperlink
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments