mirror of
https://github.com/hanzoai/azure-sdk-for-js.git
synced 2026-10-30 19:51:51 +00:00
## What - Adds a helpful error message about missing global DOM APIs when using core-xml / core-http in web workers - Adds a sample and document demonstrating possible workarounds and polyfills ## Why A customer raised an issue in #11067 when trying to use @azure/storage-blob from a web worker. Because we use DOM APIs which are not available for web workers, customers using Storage Blob (and any other library that depends on XML) in workers will see a few errors: 1. `document` is not defined 2. `window` is not defined (fixed in #13873) We decided in a previous PR (see https://github.com/Azure/azure-sdk-for-js/pull/13977#issuecomment-786273058) on some guidelines for supporting platforms other than browsers and node out of the box. And bundling a heavy XML library such as `xml2js` to support web workers did not meet the criteria of support we want to provide. What this change offers is a better error message when we detect global dependencies are missing and a sample demonstrating how I might use an XML / DOM library to provide this functionality in web workers. Resolves #11067
20 lines
363 B
JavaScript
20 lines
363 B
JavaScript
const { JSDOM } = require("jsdom");
|
|
|
|
const { window } = new JSDOM();
|
|
|
|
if (!globalThis.document) {
|
|
globalThis.document = window.document;
|
|
}
|
|
|
|
if (!globalThis.DOMParser) {
|
|
globalThis.DOMParser = window.DOMParser;
|
|
}
|
|
|
|
if (!globalThis.XMLSerializer) {
|
|
globalThis.XMLSerializer = window.XMLSerializer;
|
|
}
|
|
|
|
if (!globalThis.Node) {
|
|
globalThis.Node = window.Node;
|
|
}
|