@pendo/agent 2.275.1 → 2.276.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -45,7 +45,7 @@ The object returned by calling `initialize` is the same as a snippet install of
45
45
  | key | required? | type | description |
46
46
  | --- | --------- | ---- | ---------- |
47
47
  | apiKey | required | string | Your specific application `apiKey` can be found by going to the application details page in the Pendo App for your application. It will be a 32-digit code that identifies that application and connects it to Pendo. |
48
- | env | required | string | The environment that your Pendo subscription resides in. `io` is the default US environment and environments other than that can be found in the url that you use to access Pendo (e.g. app.`eu`.pendo.io). One of: ['io', 'eu', 'jpn', 'us1', 'au']. |
48
+ | env | required | string | The environment that your Pendo subscription resides in. `io` is the default US environment and environments other than that can be found in the url that you use to access Pendo (e.g. app.`eu`.pendo.io). One of: ['io', 'eu', 'jpn', 'us1', 'au', 'gov']. |
49
49
  | visitor | optional | object | The visitor information for the current user of your application. This includes the `id` and any other metadata you want attached to the visitor. If not provided the visitor will be treated as an anonymous visitor. |
50
50
  | account | optional | object | The account information for the current user of your application if applicable. If not provided the visitor will not be assigned to an account. |
51
51
  | globalKey | optional | string | The key where you would like the global `pendo` object to be stored after initialization. By default this will be stored on `window.pendo` but this allows it to change to a different name if desired. |
package/dist/dom.esm.js CHANGED
@@ -7094,7 +7094,11 @@ var sniffer = {
7094
7094
 
7095
7095
  // other node types can be read about here:
7096
7096
  // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
7097
+ var TEXT = 3;
7097
7098
  var ELEMENT = 1;
7099
+ var DOCUMENT = 9;
7100
+ var DOCUMENT_FRAGMENT = 11;
7101
+ var CDATA_SECTION = 4;
7098
7102
  function isElementNode(node) {
7099
7103
  return node && node.nodeType === ELEMENT;
7100
7104
  }
@@ -7224,7 +7228,7 @@ function getScreenPosition(element) {
7224
7228
  };
7225
7229
  }
7226
7230
 
7227
- var VERSION = '2.275.1_';
7231
+ var VERSION = '2.276.0_';
7228
7232
  function isExtensionAgent() {
7229
7233
  var installType = getPendoConfigValue('installType') || getPendoConfigFromEnclosingScope().installType;
7230
7234
  return installType === EXTENSION_INSTALL_TYPE;
@@ -9594,6 +9598,221 @@ DomQuery.$ = {
9594
9598
  }
9595
9599
  };
9596
9600
 
9601
+ /**
9602
+ * Abstraction on top of Mutation Observer that has a naive polyfill to use setTimeout and look
9603
+ * every half second for changes.
9604
+ *
9605
+ * This observer only attempts to verify changes to `isInDocument` status for all "observed" elements.
9606
+ * The side effect of changing status is left to the element and any code owning said element to handle.
9607
+ */
9608
+ var DomObserver = /** @class */ (function () {
9609
+ function DomObserver(container, config) {
9610
+ if (container === void 0) { container = getBody(); }
9611
+ if (config === void 0) { config = { 'attributes': true, 'childList': true, 'subtree': true }; }
9612
+ var _this = this;
9613
+ this.listeners = [];
9614
+ this._teardown = function () { };
9615
+ if (sniffer.MutationObserver) {
9616
+ var MutationObserver_1 = getZoneSafeMethod('MutationObserver');
9617
+ var observer_1 = new MutationObserver_1(function (mutationList, observer) {
9618
+ _this.signal();
9619
+ });
9620
+ observer_1.observe(container, config);
9621
+ this._teardown = function () { return observer_1.disconnect; };
9622
+ }
9623
+ else {
9624
+ var handle_1 = setTimeout$1(function () {
9625
+ _this.signal();
9626
+ }, 500);
9627
+ this._teardown = function () {
9628
+ clearTimeout(handle_1);
9629
+ };
9630
+ }
9631
+ }
9632
+ DomObserver.prototype.signal = function () {
9633
+ _.each(this.listeners, function (el) {
9634
+ el.get();
9635
+ });
9636
+ };
9637
+ DomObserver.prototype.addObservers = function () {
9638
+ var elements = [];
9639
+ for (var _i = 0; _i < arguments.length; _i++) {
9640
+ elements[_i] = arguments[_i];
9641
+ }
9642
+ this.listeners = [].concat(this.listeners, elements);
9643
+ };
9644
+ DomObserver.prototype.teardown = function () {
9645
+ this._teardown();
9646
+ };
9647
+ return DomObserver;
9648
+ }());
9649
+
9650
+ function WeakRefFactory() {
9651
+ function WeakRef(obj) {
9652
+ this._object = obj;
9653
+ }
9654
+
9655
+ WeakRef.prototype.deref = function() {
9656
+ return this._object;
9657
+ };
9658
+
9659
+ return WeakRef;
9660
+ }
9661
+
9662
+ var WeakRef = (function(global, factory) {
9663
+ var nativeWeakRef = global.WeakRef;
9664
+ if (typeof nativeWeakRef !== 'function' || !/native/.test(nativeWeakRef)) {
9665
+ return factory();
9666
+ }
9667
+
9668
+ return nativeWeakRef;
9669
+ })(window, WeakRefFactory);
9670
+
9671
+ function getText(elem, limit) {
9672
+ var ret = '';
9673
+ var nodeType = elem.nodeType;
9674
+ var sub;
9675
+ limit = limit || 128;
9676
+ if (nodeType === TEXT || nodeType === CDATA_SECTION) {
9677
+ return elem.nodeValue;
9678
+ }
9679
+ else if (!isElemBlacklisted(elem) &&
9680
+ (nodeType === ELEMENT ||
9681
+ nodeType === DOCUMENT ||
9682
+ nodeType === DOCUMENT_FRAGMENT)) {
9683
+ // Traverse its children
9684
+ if (!elem.childNodes)
9685
+ return ret;
9686
+ for (var i = 0; i < elem.childNodes.length; ++i) {
9687
+ var child = elem.childNodes[i];
9688
+ sub = getText(child, limit - ret.length);
9689
+ if ((ret + sub).length >= limit) {
9690
+ return ret + trimSurrogate(sub.substring(0, limit - ret.length));
9691
+ }
9692
+ ret += sub;
9693
+ }
9694
+ }
9695
+ return ret;
9696
+ }
9697
+ function isElemBlacklisted(elem) {
9698
+ return !elem.tagName || elem.tagName.toLowerCase() == 'textarea';
9699
+ }
9700
+ /**
9701
+ * Determine if the supplied {codepoint} falls within the "high surrogate" range
9702
+ * of unicode characters.
9703
+ *
9704
+ * @access private
9705
+ * @param {number} codepoint
9706
+ * @returns {boolean}
9707
+ * @see https://en.wikipedia.org/wiki/UTF-16#U.2BD800_to_U.2BDFFF
9708
+ */
9709
+ function isHighSurrogate(codepoint) {
9710
+ return (0xD800 <= codepoint && codepoint <= 0xDBFF);
9711
+ }
9712
+ /**
9713
+ * Determine if the supplied {codepoint} falls within the "low surrogate" range
9714
+ * of unicode characters.
9715
+ *
9716
+ * @access private
9717
+ * @param {number} codepoint
9718
+ * @returns {boolean}
9719
+ * @see https://en.wikipedia.org/wiki/UTF-16#U.2BD800_to_U.2BDFFF
9720
+ */
9721
+ function isLowSurrogate(codepoint) {
9722
+ return (0xDC00 <= codepoint && codepoint <= 0xDFFF);
9723
+ }
9724
+ /**
9725
+ * Remove "high surrogate" or unmatched "low surrogate" characters from the end
9726
+ * of {s}, indicating a broken unicode glyph. This happens when we truncate the
9727
+ * text of a node in {getText} that ends with a double-byte-encoded unicode glyph
9728
+ * such as emoji.
9729
+ *
9730
+ * @access private
9731
+ * @see https://github.com/pendo-io/pendo-client/pull/12
9732
+ * @param {string} s
9733
+ * @returns {string} s if no trailing surrogates, s-1 otherwise
9734
+ */
9735
+ function trimSurrogate(s) {
9736
+ // If the string is empty, it's definitely _not_ a "lonely surrogate"...
9737
+ if (s.length < 1)
9738
+ return s;
9739
+ var last = s.slice(-1).charCodeAt(0);
9740
+ // We're only interested in the `last` character...
9741
+ if (!isHighSurrogate(last) && !isLowSurrogate(last))
9742
+ return s;
9743
+ // If the string is only 1 character, that surrogate is definitely "lonely"...
9744
+ if (s.length === 1)
9745
+ return s.slice(0, -1);
9746
+ // All "lonely high surrogates" shall be eradicated...
9747
+ if (isHighSurrogate(last))
9748
+ return s.slice(0, -1);
9749
+ // Not sure how "lonely low surrogate" could happen, but let's check!
9750
+ if (isLowSurrogate(last)) {
9751
+ // Per above, the `last` character isn't the _only_ character...
9752
+ var prev = s.slice(-2).charCodeAt(0);
9753
+ // And if the `prev` character isn't a "high surrogate", that "low surrogate" is lonely.
9754
+ if (!isHighSurrogate(prev))
9755
+ return s.slice(0, -1);
9756
+ }
9757
+ return s; // otherwise leave it alone
9758
+ }
9759
+
9760
+ var ElementGetter = /** @class */ (function () {
9761
+ function ElementGetter(cssSelector) {
9762
+ this.listeners = {}; // callbacks to be called when an event of type occurs
9763
+ this.events = []; // event types this element listens for
9764
+ this.cssSelector = cssSelector;
9765
+ }
9766
+ ElementGetter.prototype.get = function () {
9767
+ var _this = this;
9768
+ var el = this.elRef && this.elRef.deref();
9769
+ var isInDoc = isInDocument(el); // is this safe to call if el is null?
9770
+ if (el && isInDoc)
9771
+ return el;
9772
+ if (el && !isInDoc) {
9773
+ return undefined;
9774
+ }
9775
+ el = dom(this.cssSelector)[0];
9776
+ if (!el) {
9777
+ return undefined;
9778
+ }
9779
+ _.each(this.events, function (evtType) {
9780
+ el.addEventListener(evtType, function (e) { return _this.onEvent(e); });
9781
+ });
9782
+ this.elRef = new WeakRef(el);
9783
+ return el;
9784
+ };
9785
+ ElementGetter.prototype.getText = function (limit) {
9786
+ if (limit === void 0) { limit = 1024; }
9787
+ // XXX not sure about size limit
9788
+ return getText(this.get(), limit);
9789
+ };
9790
+ ElementGetter.prototype.addEventListener = function (event, callback) {
9791
+ var _this = this;
9792
+ var el = this.get();
9793
+ if (this.events.indexOf(event) < 0) {
9794
+ this.events.push(event);
9795
+ if (el) {
9796
+ el.addEventListener(event, function (e) { return _this.onEvent(e); });
9797
+ }
9798
+ }
9799
+ this.listeners[event] = this.listeners[event]
9800
+ ? this.listeners[event].push(callback) : [].concat(callback);
9801
+ };
9802
+ ElementGetter.prototype.onEvent = function (evt) {
9803
+ var type = evt.type;
9804
+ _.each(this.listeners[type], function (cb) { return cb(evt); });
9805
+ };
9806
+ ElementGetter.prototype.teardown = function () {
9807
+ var _this = this;
9808
+ var el = this.get();
9809
+ if (el) {
9810
+ _.each(this.events, function (evtType) { return el.removeEventListener(evtType, _this.onEvent); });
9811
+ }
9812
+ };
9813
+ return ElementGetter;
9814
+ }());
9815
+
9597
9816
  _.extend(dom, {
9598
9817
  'data': DomData$1,
9599
9818
  'event': DomEvent,
@@ -9608,6 +9827,8 @@ _.extend(dom, {
9608
9827
  'intersectRect': intersectRect,
9609
9828
  'getScrollParent': getScrollParent,
9610
9829
  'isElementVisible': isElementVisible,
9830
+ 'Observer': DomObserver,
9831
+ 'Element': ElementGetter,
9611
9832
  'scrollIntoView': scrollIntoView,
9612
9833
  'getRootNode': getRootNode
9613
9834
  });