How to Detect Failed Requests via Web Extensions
One of the best things that ever happened to t he user experience of the web has been web extensions. Browsers are powerful but extensions bring a new level of functionality. Whether it’s crypto wallets, media players, or other popular plugins, web extensions have become essential to every day tasks.
Working on MetaMask, I am thrust into a world of making everything Ethereum-centric work. One of those functionalities is ensuring that .eth
domains resolve to ENS when input to the address bar. Requests to https://vitalik.eth
naturally fail, since .eth
isn’t a natively supported top level domain, so we need to intercept this errant request.
// Add an onErrorOccurred event via the browser.webRequest extension API browser.webRequest.onErrorOccurred.addListener((details) => { const { tabId, url } = details; const { hostname } = new URL(url); if(hostname.endsWith('.eth')) { // Redirect to wherever I want the user to go browser.tabs.update(tabId, { url: `https://app.ens.domains/${hostname}}` }); } }, { urls:[`*://*.eth/*`], types: ['main_frame'], });
Web extensions provide a browser.webRequest.onErrorOccurred
method that developers can plug into to listen for errant requests. This API does not catch 4**
and 5**
response errors. In the case above, we look for .eth
hostnames and redirect to ENS.
You could employ onErrorOccurred
for any number of reasons, but detecting custom hostnames is a great one!
Contents
Conquering Impostor Syndrome
Two years ago I documented my struggles with Imposter Syndrome and the response was immense. I received messages of support and commiseration from new web developers, veteran engineers, and even persons of all experience levels in other professions. I’ve even caught myself reading the post…
How to Create a RetroPie on Raspberry Pi – Graphical Guide
Today we get to play amazing games on our super powered game consoles, PCs, VR headsets, and even mobile devices. While I enjoy playing new games these days, I do long for the retro gaming systems I had when I was a kid: the original Nintendo…
Editable Content Using MooTools 1.2, PHP, and MySQL
Everybody and their aerobics instructor wants to be able to edit their own website these days. And why wouldn’t they? I mean, they have a $500 budget, no HTML/CSS experience, and extraordinary expectations. Enough ranting though. Having a website that allows for…
CSS Kwicks
One of the effects that made me excited about client side and JavaScript was the Kwicks effect. Take a list of items and react to them accordingly when hovered. Simple, sweet. The effect was originally created with JavaScript but come five years later, our…
[ad_2]
Source link