Firefox扩展中的BlockingResponse



我正试图在Firefox扩展中重定向用户,如下所示:

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"]
);

我已经在清单中添加了webRequest和webRequestBlocking权限。在调试器中,我看到我正在使用正确设置的重定向URL到达返回语句,但网页没有重定向。我认为这应该基于webRequest文档进行重定向,但是临时扩展似乎没有重定向。关于如何让扩展重定向,有什么想法吗?将url更改为https://www.google.com例如,也不起作用,所以问题似乎与URL无关。

经过一些测试,我确定问题出在类型数组上。xmlhttprequest在Firefox中不捕获某些请求,但在Chrome中捕获。为了仍然能够重定向,类型应该如下:

types: [
"main_frame",
"xmlhttprequest"]

相关内容

  • 没有找到相关文章

最新更新