I'm attempting to redirect a user in a Firefox extension like so:
browser.webRequest.onBeforeRequest.addListener(
({ url }) => {
const [fullMatch, type, identifier] =
url.match(
/open\.spotify\.com\/(track|album|artist|playlist|concert|episode|show|user)\/([^\&\#\/\?]+)/i
) || [];
return { redirectUrl: `spotify:${type}:${identifier}` };
},
{
urls: ["*://open.spotify.com/track/*", "*://open.spotify.com/album/*",
"*://open.spotify.com/artist/*", "*://open.spotify.com/playlist/*",
"*://open.spotify.com/concert/*", "*://open.spotify.com/episode/*",
"*://open.spotify.com/show/*", "*://open.spotify.com/user/*"],
types: ["xmlhttprequest"],
},
["blocking"]
);
I've added webRequest and webRequestBlocking permissions in the manifest. In the debugger, I see that I am reaching the return statement with the redirectUrl correctly set, but the webpage does not redirect. I would assume this should redirect based upon the webRequest documentation, however the temporary extension does not seem to redirect. Any ideas on how to get the extension to redirect? Changing the url to https://www.google.com, for example, doesn't work either, so it seems the issue is not with the URL.
redirectUrl
must be a proper URL whilespotify:${type}:${identifier}
doesnt appear to be.