[英]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.