Firefox 扩展中的 BlockingResponse
BlockingResponse in Firefox extension
我正在尝试像这样在 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 权限。在调试器中,我看到我到达了正确设置了 redirectUrl 的 return 语句,但网页没有重定向。我假设这应该基于 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 重定向,例如,也不起作用,所以问题似乎不在于 URL.
经过一些测试,我确定问题出在 types 数组上。 xmlhttprequest 不捕获 Firefox 中的某些请求,但在 Chrome 中捕获。为了仍然能够重定向,类型应如下所示:
types: [
"main_frame",
"xmlhttprequest"]
我正在尝试像这样在 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 权限。在调试器中,我看到我到达了正确设置了 redirectUrl 的 return 语句,但网页没有重定向。我假设这应该基于 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 重定向,例如,也不起作用,所以问题似乎不在于 URL.
经过一些测试,我确定问题出在 types 数组上。 xmlhttprequest 不捕获 Firefox 中的某些请求,但在 Chrome 中捕获。为了仍然能够重定向,类型应如下所示:
types: [
"main_frame",
"xmlhttprequest"]