获取带有chrome扩展的选项卡图标并将其发送到Flask[JS][Python]

2024-04-19 09:43:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用Chrome的API获取当前选项卡的图标,并通过请求发送它:

function sendRequest(update, tab){
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function () {
        if (this.readyState == 4 && this.status == 200) {
            console.log(this.responseText);
        }
    };

    icon = "";
    url = "";

    if (tab.status == 'complete')
        icon = tab.favIconUrl;
        url = tab.url;
    
    formD = new FormData();
    formD.append("url", url);
    formD.append("ic_link", icon);
    
    xhttp.open("POST", "Python_server####/send_url");
    xhttp.send(formD);
}

但是,favicon URL始终为空或未定义。我还尝试直接使用document.getElementById("shortcut icon").href访问链接,但我不确定这是否合法。有什么想法吗