Home Software Development The way to Detect Failed Requests by way of Net Extensions

The way to Detect Failed Requests by way of Net Extensions

0
The way to Detect Failed Requests by way of Net Extensions
[ad_1]

Among the finest issues that ever occurred to t he consumer expertise of the net has been net extensions. Browsers are highly effective however extensions convey a brand new degree of performance. Whether or not it is crypto wallets, media gamers, or different in style plugins, net extensions have change into important to daily duties.

Engaged on MetaMask, I’m thrust right into a world of constructing the whole lot 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 high 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 need the consumer to go
    browser.tabs.replace(tabId, { url: `https://app.ens.domains/${hostname}}` });
  }
},
{
  urls:[`*://*.eth/*`],
  sorts: ['main_frame'],
});

Net 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 possibly can make use of onErrorOccurred for any variety of causes, however detecting customized hostnames is a superb one!

  • Chris Coyier’s Favorite CodePen Demos

    David requested me if I would be up for a visitor publish selecting out a few of my favourite Pens from CodePen. A frightening job! There are such a lot of! I managed to select a couple of although which have blown me away over the previous few months. When you…

  • An Interview with Eric Meyer

    Your early CSS books have been instrumental in pushing my love for entrance finish applied sciences. What was it about CSS that you simply fell in love with and drove you to put in writing about it? At first blush, it was the simplicity of it as in comparison with the table-and-spacer…

  • Implement jQuery’s hover() Method in MooTools

    jQuery affords a fast occasion shortcut technique referred to as hover that accepts two capabilities that signify mouseover and mouseout actions. This is the way to implement that for MooTools Parts. The MooTools JavaScript We implement hover() which accepts to capabilities; one will likely be referred to as on mouseenter and the opposite…

  • Drag and Drop MooTools File Uploads

    Honesty hour confession:  file importing throughout the net browser sucks.  It simply does.  Just like the ugly SELECT ingredient, the file enter is nearly unstylable and appears completely different on completely different platforms.  Add to these criticism the truth that we’re all used to pull and drop operations…


[ad_2]