All,
I am trying to work with the "@azure/storage-blob" module inside a web worker running from an Angular 13 Application.
The web worker is being called by a service inside the angular app. I am getting XML parsing errors in the Browser Console:
Uncaught (in promise) Error: This library depends on the following DOM objects: ["document", "DOMParser", "Node", "XMLSerializer"] to parse XML, but some of these are undefined. You may provide a polyfill to make these globally available in order to support your environment. For more information, please refer to https://aka.ms/azsdk/js/web-workers.
The above weblink mentions adding support for DOM objects by installing JSDOM and using pollyfill. So far I haven't managed to get anything to work with Angular. Below is the code for the web worker that caused the error:
/// <reference lib="webworker" />
import { BlobServiceClient } from '@azure/storage-blob';
import { environment } from '../../environments/environment';
const sasURL = environment.sasURL;
const blobServiceClient = new BlobServiceClient(sasURL);
const containerName = environment.containerName;
// List blobs inside a container
async function main() {
const containerClient = blobServiceClient.getContainerClient(containerName);
let i = 1;
let blobs = containerClient.listBlobsFlat();
for await (const blob of blobs) {
console.log(`Blob ${i++}: ${blob.name}`);
}
}
addEventListener('message', ({ data }) => {
const response = `worker response to ${data}`;
main();
postMessage(response);
});