ms-rest-js icon indicating copy to clipboard operation
ms-rest-js copied to clipboard

`DOMParser is not defined` error when initializing client in Web Worker

Open adamra-msft opened this issue 5 years ago • 5 comments

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:

  1. Create a web worker using code similar to the following (substitute ClientName, token, and customBaseUri for valid values--ClientName should be a client derived from msRest.ServiceClient; the other values might be optional depending on the client that is tested)
onmessage = () => {
  const client = new ClientName(new TokenCredentials(token), {
    baseUri: "customBaseUri"
  });
};
  1. Send a message to the web worker to invoke this code
  2. 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: image

Additional context N/A

adamra-msft avatar Sep 30 '20 21:09 adamra-msft

@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 avatar Jan 26 '21 23:01 jeremymeng

@jeremymeng I am having the same issue in Beekeeper Studio. The workaround suggested in the core-http issue did not work for me.

rathboma avatar May 04 '21 20:05 rathboma

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 avatar May 04 '21 20:05 rathboma

@rathboma if possible, could you please provide a simple project that demonstrates the issue when using node-mssql? That would help our investigation greatly!

jeremymeng avatar May 04 '21 20:05 jeremymeng

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.

rathboma avatar May 04 '21 20:05 rathboma