如何获取本地获取,如果已替换

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

如果替换了本地获取

window.fetch = () => {}

如果不是我的代码的代码替换了本地获取,如何获取本地获取?

javascript window fetch fetch-api
1个回答
0
投票

您不能在同一窗口中。但是您可以打开一个新窗口(可能为零高度iframe)并从那里获取它:

const iframe = document.createElement("iframe");
iframe.src = "about:blank";
iframe.style.border = "none";
iframe.style.width = 0;
iframe.style.height = 0;
iframe.addEventListener("load", function() {
    const realFetch = iframe.contentWindow.fetch;
    // ...use `realFetch` here...
});
© www.soinside.com 2019 - 2024. All rights reserved.