4

Is there any way to pass a File object via postMessage or any similar function?

I need to communicate between page-related JS code and the one from content script as stated in the documentation.

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

FrozenHeart
  • 19,844
  • 33
  • 126
  • 242

1 Answers1

1

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.

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.

Community
  • 1
  • 1
KENdi
  • 7,576
  • 2
  • 16
  • 31