observe.js 943 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. /**
  3. * Takes a performance entry type and a callback function, and creates a
  4. * `PerformanceObserver` instance that will observe the specified entry type
  5. * with buffering enabled and call the callback _for each entry_.
  6. *
  7. * This function also feature-detects entry support and wraps the logic in a
  8. * try/catch to avoid errors in unsupporting browsers.
  9. */
  10. const observe = (
  11. type,
  12. callback,
  13. opts,
  14. ) => {
  15. try {
  16. if (PerformanceObserver.supportedEntryTypes.includes(type)) {
  17. const po = new PerformanceObserver(list => {
  18. callback(list.getEntries() );
  19. });
  20. po.observe(
  21. Object.assign(
  22. {
  23. type,
  24. buffered: true,
  25. },
  26. opts || {},
  27. ) ,
  28. );
  29. return po;
  30. }
  31. } catch (e) {
  32. // Do nothing.
  33. }
  34. return;
  35. };
  36. exports.observe = observe;
  37. //# sourceMappingURL=observe.js.map