From 4d1e2907068a18fbfe01e5b3b5cca604b9083afc Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Thu, 22 Feb 2024 00:05:38 -0800 Subject: [PATCH] override: add IntersectionObserver(callback, options) constructor override, which will deproxy options.root if it is set fixes #136 --- src/wombat.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/wombat.js b/src/wombat.js index 8f94f0b..2317af4 100755 --- a/src/wombat.js +++ b/src/wombat.js @@ -4207,6 +4207,29 @@ Wombat.prototype.initBlobOverride = function() { this.$wbwindow.Blob.prototype = orig_blob.prototype; }; +Wombat.prototype.initIntersectionObsOverride = function() { + var orig_iobs = this.$wbwindow.IntersectionObserver; + + var wombat = this; + + this.$wbwindow.IntersectionObserver = (function(IObs) { + return function(callback, options) { + if (options && options.root) { + options.root = wombat.proxyToObj(options.root); + } + + return new IObs(callback, options); + }; + + })(this.$wbwindow.IntersectionObserver); + + this.$wbwindow.IntersectionObserver.prototype = orig_iobs.prototype; + + Object.defineProperty(this.$wbwindow.IntersectionObserver.prototype, 'constructor', { + value: this.$wbwindow.IntersectionObserver + }); +}; + Wombat.prototype.initWSOverride = function() { if (!this.$wbwindow.WebSocket || !this.$wbwindow.WebSocket.prototype) { return; @@ -6668,6 +6691,9 @@ Wombat.prototype.wombatInit = function() { this.overrideIframeContentAccess('contentWindow'); this.overrideIframeContentAccess('contentDocument'); + // IntersectionObserver constructor override + this.initIntersectionObsOverride(); + // override funcs to convert first arg proxy->obj this.overrideFuncArgProxyToObj(this.$wbwindow.MutationObserver, 'observe'); this.overrideFuncArgProxyToObj(