The best way to Detect Failed Requests by way of Net Extensions

on

|

views

and

comments

[ad_1]

The most effective issues that ever occurred to t he consumer expertise of the online 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 well-liked plugins, net extensions have develop into important to each day duties.

Engaged on MetaMask, I’m thrust right into a world of constructing all the pieces Ethereum-centric work. A type of functionalities is guaranteeing 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 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 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 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 might make use of onErrorOccurred for any variety of causes, however detecting customized hostnames is a good one!

  • Write Better JavaScript with Promises

    You have most likely heard the discuss across the water cooler about how guarantees are the longer term. All the cool children are utilizing them, however you do not see what makes them so particular. Cannot you simply use a callback? What is the huge deal? On this article, we’ll…

  • 6 Things You Didn’t Know About Firefox OS

    Firefox OS is all around the tech information and for good purpose:  Mozilla’s lastly given net builders the platform that they should create apps the best way they have been creating them for years — with CSS, HTML, and JavaScript.  Firefox OS has been quickly bettering…


[ad_2]
Supply hyperlink
Share this
Tags

Must-read

Google Presents 3 Suggestions For Checking Technical web optimization Points

Google printed a video providing three ideas for utilizing search console to establish technical points that may be inflicting indexing or rating issues. Three...

A easy snapshot reveals how computational pictures can shock and alarm us

Whereas Tessa Coates was making an attempt on wedding ceremony clothes final month, she posted a seemingly easy snapshot of herself on Instagram...

Recent articles

More like this

LEAVE A REPLY

Please enter your comment!
Please enter your name here