nodebb-plugin-ezoic-infinite 1.7.1 → 1.7.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/public/client.js +30 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-ezoic-infinite",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "description": "Production-ready Ezoic infinite ads integration for NodeBB 4.x",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/public/client.js CHANGED
@@ -265,7 +265,13 @@
265
265
  try {
266
266
  const id = parseInt(w.getAttribute(A_WRAPID), 10);
267
267
  if (Number.isFinite(id)) S.mountedIds.delete(id);
268
- try { S.io?.unobserve(w.querySelector(`[id^="${PH_PREFIX}"]`)); } catch (_) {}
268
+ // IMPORTANT : ne passer unobserve que si c'est un vrai Element.
269
+ // unobserve(null) corrompt l'état interne de l'IO (pubads lève ensuite
270
+ // "parameter 1 is not of type Element" sur le prochain observe).
271
+ try {
272
+ const ph = w.querySelector(`[id^="${PH_PREFIX}"]`);
273
+ if (ph instanceof Element) S.io?.unobserve(ph);
274
+ } catch (_) {}
269
275
  w.remove();
270
276
  } catch (_) {}
271
277
  }
@@ -389,7 +395,7 @@
389
395
  S.io = new IntersectionObserver(entries => {
390
396
  for (const e of entries) {
391
397
  if (!e.isIntersecting) continue;
392
- S.io?.unobserve(e.target);
398
+ if (e.target instanceof Element) S.io?.unobserve(e.target);
393
399
  const id = parseInt(e.target.getAttribute('data-ezoic-id'), 10);
394
400
  if (Number.isFinite(id) && id > 0) enqueueShow(id);
395
401
  }
@@ -637,12 +643,30 @@
637
643
  }
638
644
 
639
645
  function ensureTcfLocator() {
646
+ // Le CMP utilise une iframe nommée __tcfapiLocator pour router les
647
+ // postMessage TCF. En navigation ajaxify, NodeBB peut retirer cette
648
+ // iframe du DOM (vidage partiel du body), ce qui provoque :
649
+ // "Cannot read properties of null (reading 'postMessage')"
650
+ // "Cannot set properties of null (setting 'addtlConsent')"
651
+ // Solution : la recrée immédiatement si elle disparaît, via un observer.
640
652
  try {
641
653
  if (!window.__tcfapi && !window.__cmp) return;
642
- if (document.getElementById('__tcfapiLocator')) return;
643
- const f = document.createElement('iframe');
644
- f.style.display = 'none'; f.id = f.name = '__tcfapiLocator';
645
- (document.body || document.documentElement).appendChild(f);
654
+
655
+ const inject = () => {
656
+ if (document.getElementById('__tcfapiLocator')) return;
657
+ const f = document.createElement('iframe');
658
+ f.style.display = 'none'; f.id = f.name = '__tcfapiLocator';
659
+ (document.body || document.documentElement).appendChild(f);
660
+ };
661
+
662
+ inject();
663
+
664
+ // Observer dédié — si quelqu'un retire l'iframe, on la remet.
665
+ if (!window.__nbbTcfObs) {
666
+ window.__nbbTcfObs = new MutationObserver(() => inject());
667
+ window.__nbbTcfObs.observe(document.documentElement,
668
+ { childList: true, subtree: true });
669
+ }
646
670
  } catch (_) {}
647
671
  }
648
672