javascript - 为什么我会得到“在 'Window' 上执行 'postMessage' 失败:#使用 iframe 的 Promise 时无法克隆错误”?
问题描述
我有主机 Web 应用程序,它在 iframe 中加载具有相同域的同一应用程序的另一部分。我的代码如下所示:
const iframe = document.querySelector('iframe');
const api = iframe.contentWindow.api;
const result = await api.performAsyncAction().then(response => response.json());
执行上面的代码后,我收到以下错误消息:
Failed to execute 'postMessage' on 'Window': #<Promise> could not be cloned.
你能帮我解决这种错误吗?我知道 postMessage 用于在 iframe 和主机应用程序之间进行通信,但我需要弄清楚为什么会抛出上面的错误(我有点惊讶,因为我在这里不使用 postMessage)
更新:
performAsyncAction
方法的实现如下:
function performAsyncAction () {
return fetch("/api/request", {
method: "POST",
headers: {
Accept: 'application/json'
},
})
}
解决方案
推荐阅读
- javascript - gulpfile 只编译最后一个文件
- angular - Angular - @HostBinding() - 可以读取从 HTML 添加的类
- java - Java 12 Shell 无法在 Windows 上正确读取键盘输入
- javascript - javascript中的视口大小
- hazelcast - 有没有办法以编程方式清除 Hazelcast 缓存统计信息?
- google-apps-script - 可靠的下拉列表和 getValues() 二维数组
- javascript - 依次调用 API 直到响应为空
- python - Python中的三重数组
- java - 如何通过覆盖接口实现 Fragment-Activity 通信?
- tkinter - 为什么 pyInstaller 试图导入 tkinter?