I'm trying to send my formdata object to a service worker before submitting the form by using the postMessage() method.
I've tried multiple solutions but I always either get the cant be cloned error or empty form data.
Some of the things I've tried:
var formData = new FormData();
formData.append('photo', image);
formData.append('description', description);
// attempt 1
var msg = {
form_data: formData,
}
// attempt 2
var msg = {
form_data: JSON.stringify(formData),
}
// attempt 3
var msg = {
form_data: JSON.stringify(formData.entries()),
}
// attempt 4
console.log(msg); // form data is either empty or I get an error depending on the attempt
swRegistration.active.postMessage(msg);