vibornoff/webcrypto-shim

Provide a way to disable Promise support check

Closed this issue · 3 comments

I am including this library as a polyfill for an Angular project that is compiled with TypeScript. TypeScript already handles transpiling Promises to ES5, so a supporting promise polyfill library is not required.

When trying to require webcrypto-shim, the included Promise check causes it to throw an exception:

https://github.com/vibornoff/webcrypto-shim/blob/master/webcrypto-shim.js#L21

I can comment this line out and still use the library, however, that requires me to create a locally modified version of it which I would like to avoid having to do (would like to just use NPM). It would be good to provide some way to skip this check. I'm willing to submit a PR if you like, but I am not sure what approach you would like to take. Perhaps some global variable that allows the bypass of the check?

if ( typeof Promise !== 'function' && !window.WebCryptoShimSkipPromiseCheck )
    throw "Promise support required";

For now I have worked around this issue by doing this:

const noPromise = typeof Promise !== 'function';
if (noPromise) {
    (window as any).Promise = () => { /* Nothing */ };
}
require('webcrypto-shim');
if (noPromise) {
    (window as any).Promise = undefined;
}

Can you try this approach?

if ( typeof Promise === 'undefined' )
    throw "Promise support required";

If it would work for you I'll change it this way.

This can be closed now. I was not including the TypeScript ES6 polyfill code in the correct order which resulted in the webcrypto-shim loading too early.