Monday, January 20, 2025

Find out how to Detect Failed Requests through Net Extensions


The most effective issues that ever occurred to t he consumer expertise of the net has been net extensions. Browsers are highly effective however extensions deliver a brand new stage of performance. Whether or not it is crypto wallets, media gamers, or different common plugins, net extensions have grow to be important to every single day duties.

Engaged on MetaMask, I’m thrust right into a world of constructing the whole lot Ethereum-centric work. A kind 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 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/*`],
  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 would make use of onErrorOccurred for any variety of causes, however detecting customized hostnames is a good one!

  • Write Better JavaScript with Promises

    You’ve got in all probability heard the discuss across the water cooler about how guarantees are the long run. All the cool youngsters are utilizing them, however you do not see what makes them so particular. Cannot you simply use a callback? What is the massive deal? On this article, we’ll…

  • Create Namespaced Classes with MooTools

    MooTools has at all times gotten a little bit of grief for not inherently utilizing and standardizing namespaced-based JavaScript lessons just like the Dojo Toolkit does.  Many builders create their lessons as globals which is usually frowned up.  I principally disagree with that stance, however every to their very own.  In any occasion…

  • MooTools-Like Element Creation in jQuery

    I actually dislike jQuery’s component creation syntax. It is principally the identical as typing out HTML however inside a JavaScript string…ugly! Fortunately Basil Goldman has created a jQuery plugin that lets you create components utilizing MooTools-like syntax. Customary jQuery Ingredient Creation Seems precisely like writing out…

  • MooTools Clipboard Plugin

    The flexibility to position content material right into a consumer’s clipboard may be extraordinarily handy for the consumer. As a substitute of clicking and dragging down what could possibly be a prolonged doc, the consumer can copy the contents of a particular space by a single click on of a mouse.


Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

PHP Code Snippets Powered By : XYZScripts.com