improve formdata event detection

This commit is contained in:
Cory LaViska
2022-06-10 16:52:31 -04:00
parent 5613a3cef3
commit c850a7eae1
2 changed files with 2 additions and 19 deletions

View File

@@ -69,26 +69,8 @@ class FormDataPolyfill extends FormData {
}
}
function supportsFormDataEvent() {
const form = document.createElement('form');
let isSupported = false;
document.body.append(form);
form.addEventListener('submit', event => {
new FormData(event.target as HTMLFormElement);
event.preventDefault();
});
form.addEventListener('formdata', () => (isSupported = true));
form.dispatchEvent(new Event('submit', { cancelable: true }));
form.remove();
return isSupported;
}
function polyfillFormData() {
if (!window.FormData || supportsFormDataEvent()) {
if (!window.FormData || !('FormDataEvent' in window)) {
return;
}