Sunday, October 5, 2025
HomeJavaScriptLearn how to Detect Failed Requests through Net Extensions

Learn how to Detect Failed Requests through Net Extensions


Among the finest issues that ever occurred to t he consumer expertise of the online has been net 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 fashionable plugins, net extensions have change into important to day-after-day duties.

Engaged on MetaMask, I’m thrust right into a world of creating the whole lot Ethereum-centric work. A kind of functionalities is making certain 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 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'],
});

Net extensions present a browser.webRequest.onErrorOccurred technique 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 may make use of onErrorOccurred for any variety of causes, however detecting customized hostnames is a superb one!

  • Responsive and Infinitely Scalable JS Animations

    Again in late 2012 it was not straightforward to seek out open supply initiatives utilizing requestAnimationFrame() – that is the hook that enables Javascript code to synchronize with an online browser’s native paint loop. Animations utilizing this technique can run at 60 fps and ship implausible…

  • 9 Mind-Blowing WebGL Demos

    As a lot as builders now detest Flash, we’re nonetheless enjoying a little bit of catch as much as natively duplicate the animation capabilities that Adobe’s previous know-how supplied us.  After all we’ve canvas, an superior know-how, one which I highlighted 9 mind-blowing demos.  One other know-how obtainable…

  • Jack Rugile’s Favorite CodePen Demos

    CodePen is a tremendous supply of inspiration for code and design. I’m blown away day-after-day by the demos customers create. As you may see under, I’ve an affinity towards issues that transfer. It was tough to slender down my favorites, however right here they’re!

  • Animated 3D Flipping Menu with CSS

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments