diff --git a/lib/adapters/xhr.js b/lib/adapters/xhr.js index 42778d5f25..021da2a690 100644 --- a/lib/adapters/xhr.js +++ b/lib/adapters/xhr.js @@ -61,7 +61,7 @@ export default isXHRAdapterSupported && function (config) { } } - if (utils.isFormData(requestData) && platform.isStandardBrowserEnv) { + if (utils.isFormData(requestData) && (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv)) { requestHeaders.setContentType(false); // Let the browser set it } diff --git a/lib/platform/browser/index.js b/lib/platform/browser/index.js index 80284eb208..4ba2c7dbfa 100644 --- a/lib/platform/browser/index.js +++ b/lib/platform/browser/index.js @@ -31,6 +31,24 @@ const isStandardBrowserEnv = (() => { return typeof window !== 'undefined' && typeof document !== 'undefined'; })(); +/** + * Determine if we're running in a standard browser webWorker environment + * + * Although the `isStandardBrowserEnv` method indicates that + * `allows axios to run in a web worker`, the WebWorker will still be + * filtered out due to its judgment standard + * `typeof window !== 'undefined' && typeof document !== 'undefined'`. + * This leads to a problem when axios post `FormData` in webWorker + */ + const isStandardBrowserWebWorkerEnv = (() => { + return ( + typeof WorkerGlobalScope !== 'undefined' && + self instanceof WorkerGlobalScope && + typeof self.importScripts === 'function' + ); +})(); + + export default { isBrowser: true, classes: { @@ -39,5 +57,6 @@ export default { Blob }, isStandardBrowserEnv, + isStandardBrowserWebWorkerEnv, protocols: ['http', 'https', 'file', 'blob', 'url', 'data'] };