isSupported.mjs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. Copyright 2018 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.mjs';
  8. let cachedIsSupported = undefined;
  9. /**
  10. * This is a utility method that determines whether the current browser supports
  11. * the features required to create streamed responses. Currently, it checks if
  12. * [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream)
  13. * can be created.
  14. *
  15. * @return {boolean} `true`, if the current browser meets the requirements for
  16. * streaming responses, and `false` otherwise.
  17. *
  18. * @memberof workbox.streams
  19. */
  20. function isSupported() {
  21. if (cachedIsSupported === undefined) {
  22. // See https://github.com/GoogleChrome/workbox/issues/1473
  23. try {
  24. new ReadableStream({start() {}});
  25. cachedIsSupported = true;
  26. } catch (error) {
  27. cachedIsSupported = false;
  28. }
  29. }
  30. return cachedIsSupported;
  31. }
  32. export {isSupported};