我正嘗試使用Firefox本機訊息創建網址檢查器。問題是,當本地應用程序發送判決時,onBeforeRequest偵聽器已經釋放請求,因此重定向不會發生。 如果回答爲「0」,您可以請求幫助使我的擴展等待最多2秒的回覆並重定向請求嗎?使用Firefox本機訊息進行網址檢查
var port = browser.runtime.connectNative("ping_pong");
function inspectURL(requestDetails) {
console.log("Loading: <" + requestDetails.url + ">");
port.postMessage(requestDetails.url);
console.log("Posting complete <" + requestDetails.url + ">");
}
port.onMessage.addListener((response) = > {
console.log("Received: <" + response + ">");
if (response == "1")
{
console.log("Good url!!!");
}
else
{
console.log("BAD url - redirecting!!!");
return {
redirectUrl: "https://38.media.tumblr.com/tumblr_ldbj01lZiP1qe0eclo1_500.gif"
};
}
});
browser.webRequest.onBeforeRequest.addListener(
inspectURL,
{ urls: ["<all_urls>"] },
["blocking"]
);