16.8 C
New York
Sunday, May 18, 2025

The right way to Detect Failed Requests through Internet Extensions


Probably the greatest issues that ever occurred to t he consumer expertise of the net has been internet extensions. Browsers are highly effective however extensions carry a brand new stage of performance. Whether or not it is crypto wallets, media gamers, or different in style plugins, internet extensions have turn into important to day by day duties.

Engaged on MetaMask, I’m thrust right into a world of creating all the pieces Ethereum-centric work. A type of functionalities is making certain that .eth domains resolve to ENS when enter to the deal with bar. Requests to https://vitalik.ethnaturally fail, since .eth is not a natively supported high stage area, so we have to intercept this errant request.

// Add an onErrorOccurred occasion through 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 technique 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 can make use of onErrorOccurred for any variety of causes, however detecting customized hostnames is a good one!

  • How to Create a RetroPie on Raspberry Pi – Graphical Guide

    Right this moment we get to play wonderful video games on our tremendous powered sport consoles, PCs, VR headsets, and even cell gadgets.  Whereas I get pleasure from enjoying new video games lately, I do lengthy for the retro gaming methods I had after I was a child: the unique Nintendo…

  • CSS Animations Between Media Queries

    CSS animations are proper up there with sliced bread. CSS animations are environment friendly as a result of they are often {hardware} accelerated, they require no JavaScript overhead, and they’re composed of little or no CSS code. Very often we add CSS transforms to components through CSS throughout…


Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles