How you can Detect Failed Requests by way of Net Extensions


Among the best issues that ever occurred to t he person 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 well-liked plugins, internet extensions have turn into important to each day duties.

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

Net 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!

  • Regular Expressions for the Rest of Us

    In the end you will run throughout an everyday expression. With their cryptic syntax, complicated documentation and big studying curve, most builders accept copying and pasting them from StackOverflow and hoping they work. However what in the event you might decode common expressions and harness their energy? In…

  • Serving Fonts from CDN

    For optimum efficiency, everyone knows we should put our belongings on CDN (one other area).  Together with these belongings are customized internet fonts.  Sadly customized internet fonts by way of CDN (or any cross-domain font request) do not work in Firefox or Web Explorer (accurately so, by spec) although…

  • Drag. Drop. Lock.
  • Redacted Font

    Again once I created consumer web sites, one of many many issues that pissed off me was the preliminary design handoff.  It might all the time go like this: Work onerous to include consumer’s concepts, dream up superior design. Create stated design, utilizing Lorem Ipsum textual content Ship preliminary design idea to the consumer…


Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles