如何使用firefox扩展获取页面状态?

问题描述 投票:0回答:1

我想获得40 *或30 *等页面状态代码。当content_script.js执行时,Firefox扩展可以在页面加载时获取状态。但是当页面未加载时(3xx或4xx错误),内容脚本不会执行。如何检查未加载具有特定URL的选项卡?

firefox-addon firefox-webextensions
1个回答
0
投票

为此,您需要在background.js中处理onHeadersReceived事件。您可以参考文档here

browser.webRequest.onHeadersReceived.addListener(function(details){
    if(!details.initiator)
    {
        alert(details.url+" "+details.statusCode);
    }
},
{
    urls: ["<all_urls>"]
},
["responseHeaders", "blocking"]);

在您的manifest.json中,您需要添加

"permissions": ["webRequest","webRequestBlocking","<all_urls>"],
© www.soinside.com 2019 - 2024. All rights reserved.