Friday, May 24, 2024
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

Probably the greatest issues that ever occurred to t he person expertise of the online has been net extensions. Browsers are highly effective however extensions carry a brand new degree of performance. Whether or not it is crypto wallets, media gamers, or different well-liked plugins, net extensions have grow to be important to on daily basis duties.

Engaged on MetaMask, I’m thrust right into a world of creating 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 person to go
    browser.tabs.replace(tabId, { url: `${hostname}}` });
  varieties: ['main_frame'],

Internet extensions present a browser.webRequest.onErrorOccurred methodology that builders can plug into to pay attention 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 would make use of onErrorOccurred for any variety of causes, however detecting customized hostnames is a superb one!

  • Introducing MooTools LinkAlert

    One in every of my favourite Firefox plugins is known as LinkAlert. LinkAlert exhibits the person an icon after they hover over a particular hyperlink, like a hyperlink to a Microsoft Phrase DOC or a PDF file. I like that warning as a result of I hate the shock…

  • Chris Coyier’s Favorite CodePen Demos IV

    Do you know you possibly can triple-heart issues on CodePen? We’ve had that little not-so-hidden characteristic ceaselessly. You’ll be able to click on that little coronary heart button on any Pen (or Undertaking, Assortment, or Put up) on CodePen to indicate the creator slightly love, however you possibly can click on it once more…



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments