9.7 C
New York
Wednesday, November 27, 2024

The best way to detect failed requests by means of net extensions


Top-of-the-line issues that has occurred to the person expertise on the internet has been net extensions. Browsers are highly effective, however extensions carry a brand new stage of performance. Whether or not it is crypto wallets, media gamers, or different in style plugins, net extensions have turn out to be important for each day duties.

Working at MetaMask, I discover myself immersed in a world the place every little thing Ethereum-centric works. A kind of options is to make sure that .eth Domains resolve to ENS when entered within the deal with bar. Requests for https://vitalik.ethnaturally fails, since .eth just isn’t a natively supported top-level area, so we have to intercept this failed 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 person to go
    browser.tabs.replace(tabId, { url: `https://app.ens.domains/${hostname}}` });
  }
},
{
  urls:(`*://*.eth/*`),
  sorts: ('main_frame'),
});

Internet extensions present a browser.webRequest.onErrorOccurred methodology that builders can hook up with to pay attention for failed requests. This API does No catch 4** and 5** response errors. Within the earlier case we search for .eth hostnames and redirect to ENS.

you possibly can use onErrorOccurred for a number of causes, however detecting customized hostnames is nice!

  • MooTools Typewriter Effect Plugin Update
  • 3D rotating menu animated with CSS

Related Articles

Latest Articles