// match pattern for the URLs to redirect var pattern = "*://*.wikipedia.org/*"; // redirect function // returns an object with a property `redirectURL` // set to the new URL function redirect(requestDetails) { var url = new URL(requestDetails.url); if (url.host.includes(".m.wikipedia.org")) { url.href = url.href.replace(".m.wikipedia.org", ".wikipedia.org"); console.log("Redirecting: " + url.href); return { redirectUrl: url.href }; } } // add the listener, // passing the filter argument and "blocking" browser.webRequest.onBeforeRequest.addListener ( redirect, {urls:[pattern], types:["main_frame"]}, ["blocking"] );