ms-rest-js
ms-rest-js copied to clipboard
`DOMParser is not defined` error when initializing client in Web Worker
Package Version: 2.0.8
- [ ] nodejs
- nodejs version: ______
- os name/version: _____
- [x] browser
- name/version: Chrome Version 85.0.4183.121
Describe the bug
When initializing a ms-rest-js client within a web worker, an error is thrown: DOMParser is not defined. DOMParser is not available within a web worker. This prevents the client from being used from within a web worker.
To Reproduce Steps to reproduce the behavior:
- Create a web worker using code similar to the following (substitute
ClientName,token, andcustomBaseUrifor valid values--ClientNameshould be a client derived frommsRest.ServiceClient; the other values might be optional depending on the client that is tested)
onmessage = () => {
const client = new ClientName(new TokenCredentials(token), {
baseUri: "customBaseUri"
});
};
- Send a message to the web worker to invoke this code
- Note error logged in browser console:
Uncaught ReferenceError: DOMParser is not defined
at Module.../../node_modules/@azure/ms-rest-js/es/lib/util/xml.browser.js (xml.browser.js:3)
at __webpack_require__ (bootstrap:19)
at Module.../../node_modules/@azure/ms-rest-js/es/lib/policies/deserializationPolicy.js (deserializationPolicy.js:1)
at __webpack_require__ (bootstrap:19)
at Module.../../node_modules/@azure/ms-rest-js/es/lib/serviceClient.js (serviceClient.js:1)
at __webpack_require__ (bootstrap:19)
at Module.../../node_modules/@azure/ms-rest-js/es/lib/msRest.js (msRest.js:1)
at __webpack_require__ (bootstrap:19)
Expected behavior The client should initialize successfully within a web worker.
Screenshots
Screenshot of error in browser console:

Additional context N/A
@adamra-msft We use DOM api to parse and build XML in browsers. Web Worker don't have access to DOM api. We are still investigate a proper fix. In the mean time, would the workaround suggested here work for you?
@jeremymeng I am having the same issue in Beekeeper Studio. The workaround suggested in the core-http issue did not work for me.
I'm only looking to use the node-mssql library which depends on tedious. I'm not sure why they need this library, but so it is.
@rathboma if possible, could you please provide a simple project that demonstrates the issue when using node-mssql? That would help our investigation greatly!
So this isn't a self-contained reproduction, but Beekeeper is FOSS, so if you are able you can check out this branch:
- https://github.com/beekeeper-studio/beekeeper-studio/pull/641
Then yarn install, yarn electron:serve to start it, you can connect to any database, the easiest is Beekeeper's own db: help -> add Beekeepers Db Then go to a table, right click, export. You'll see the error in the console.