简体   繁体   English

如何通过postMessage或任何类似的函数传递File对象

[英]How to pass a File object via postMessage or any similar function

Is there any way to pass a File object via postMessage or any similar function? 有没有办法通过postMessage或任何类似的函数传递File对象?

I need to communicate between page-related JS code and the one from content script as stated in the documentation . 我需要在页面相关的JS代码和内容脚本之间进行通信,如文档中所述。

If I try to pass it directly it gives me the following error: 如果我尝试直接传递它,它会给我以下错误:

Uncaught DataCloneError: Failed to execute 'postMessage' on 'Window': An object could not be cloned 未捕获的DataCloneError:无法在'Window'上执行'postMessage':无法克隆对象

The Uncaught DataCloneError: Failed to execute 'postMessage' on 'Window': An object could not be cloned error message appears when postMessage sends an unsuported object as a parameter. Uncaught DataCloneError: Failed to execute 'postMessage' on 'Window': An object could not be cloned当postMessage将未导出的对象作为参数发送时, Uncaught DataCloneError: Failed to execute 'postMessage' on 'Window': An object could not be cloned错误消息。

Check this page on how to play with channel message. 查看此页面 ,了解如何播放频道消息。

Based on this SO question , alternative way is to use an array of the backing ArrayBuffer instances of any typed arrays you wish to pass. 基于这个SO问题 ,另一种方法是使用您希望传递的任何类型数组的后备ArrayBuffer实例的数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Web Worker中编码对象以使其通过postMessage传递? - How do you encode an Object in a Web Worker for it to be passed via postMessage? 如何通过 JavaScript - postMessage() 中的 web worker 传递可转移对象数组,即缓冲区以及不可转移的 object,即 json obj? - How to pass array of transferable objects i.e. buffer along with non transferable object i.e. json obj via web worker in JavaScript - postMessage()? 如何通过JavaScript对象数组传递带参数的函数? - How to pass a function with arguments via JavaScript object array? 如何通过postMessage执行一个函数 - How to execute a function through postMessage 如何将变量传递给我的回调函数或类似函数 - How to pass variable to my callback function or similar 如何通过对象传递道具 - How to pass props via an object 通过 html 按钮将对象传递给 javascript 中的函数 - Pass object to function in javascript via html button 如何使用 postMessage API 发送 javascript 对象 - how to send javascript object with postMessage API 如何在Kotlin中传递带有参数的函数引用? 类似于javascript中的bind() - How to pass function reference with parameters in kotlin? Similar to bind() in javascript 如何在.then内部传递JS函数的参数,或实现类似行为? - How to pass a parameter for a JS function inside .then, or achieve similar behavior?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM