I’ve made a chrome extension that uses an allow list of urls that you can visit, defined in extension option, if not your are redirected to a defined page.
So let say I only allow the site example.com and when visting any other site it will send me back to example.com, BUT if example.com itself redirect to a login page that’s not on the list it will loop. Of course the best way is to add the login page to the allowed list but if I want to avoid this, are there a better approach to stop a redirect loop?
example of code in content script of the extension:
let homepage = "https://example.com";
let allowlist = "https://example.com";
function TriggerAllowSites() {
let currentUrl = window.location.href;
let match = currentUrl.match(allowlist);
if (match && match.length > 0) {
console.log("We are allowed here");
} else {
window.location.href = homepage;
}
}
TriggerAllowSites()