canConstructReadableStream.js 975 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. Copyright 2019 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import '../_version.js';
  8. let supportStatus;
  9. /**
  10. * A utility function that determines whether the current browser supports
  11. * constructing a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream)
  12. * object.
  13. *
  14. * @return {boolean} `true`, if the current browser can successfully
  15. * construct a `ReadableStream`, `false` otherwise.
  16. *
  17. * @private
  18. */
  19. function canConstructReadableStream() {
  20. if (supportStatus === undefined) {
  21. // See https://github.com/GoogleChrome/workbox/issues/1473
  22. try {
  23. new ReadableStream({ start() { } });
  24. supportStatus = true;
  25. }
  26. catch (error) {
  27. supportStatus = false;
  28. }
  29. }
  30. return supportStatus;
  31. }
  32. export { canConstructReadableStream };