Skip to content

Commit ff0bdb3

Browse files
fix(ADA-3472): Remove SDK iframes from accessibility tree (#269)
* fix(ADA-3472): Remove SDK iframes from accessibility tree * ADA-3472 - Prettier * ADA-3472 - Add adsContainerObserver to initMembers
1 parent eda7b4e commit ff0bdb3

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/ima.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ class Ima extends BasePlugin implements IMiddlewareProvider, IAdsControllerProvi
254254
_adVideoTagAlreadyPlayed: boolean = false;
255255
_adStartedEvent: any = null;
256256
_engine: any = null;
257+
_adsContainerObserver: ?MutationObserver = null;
257258

258259
/**
259260
* Whether the ima plugin is valid.
@@ -578,6 +579,10 @@ class Ima extends BasePlugin implements IMiddlewareProvider, IAdsControllerProvi
578579
this._adDisplayContainer.destroy();
579580
this._adDisplayContainer = null;
580581
}
582+
if (this._adsContainerObserver) {
583+
this._adsContainerObserver.disconnect();
584+
this._adsContainerObserver = null;
585+
}
581586
}
582587

583588
/**
@@ -681,6 +686,7 @@ class Ima extends BasePlugin implements IMiddlewareProvider, IAdsControllerProvi
681686
this._nextPromise = null;
682687
this._currentAd = null;
683688
this._adsManager = null;
689+
this._adsContainerObserver = null;
684690
this._contentComplete = false;
685691
this._isAdsManagerLoaded = false;
686692
this._videoLastCurrentTime = null;
@@ -844,6 +850,38 @@ class Ima extends BasePlugin implements IMiddlewareProvider, IAdsControllerProvi
844850
// Append the ads container to the dom
845851
Utils.Dom.appendChild(playerView, this._adsContainerDiv);
846852
this._adDisplayContainer = new this._sdk.AdDisplayContainer(this._adsContainerDiv, this.player.getVideoElement());
853+
// Set up MutationObserver to handle dynamically created iframes
854+
this._setupIframeObserver();
855+
}
856+
857+
/**
858+
* Sets up a MutationObserver to apply accessibility attributes to IMA SDK iframes.
859+
* @private
860+
* @returns {void}
861+
* @instance
862+
* @memberof Ima
863+
*/
864+
_setupIframeObserver(): void {
865+
if (this._adsContainerObserver) {
866+
return;
867+
}
868+
869+
const applyAccessibility = () => {
870+
const iframes = this._adsContainerDiv.querySelectorAll('iframe');
871+
iframes.forEach(iframe => {
872+
iframe.setAttribute('aria-hidden', 'true');
873+
iframe.setAttribute('tabindex', '-1');
874+
});
875+
};
876+
877+
// Apply to any existing iframes
878+
applyAccessibility();
879+
880+
this._adsContainerObserver = new MutationObserver(applyAccessibility);
881+
this._adsContainerObserver.observe(this._adsContainerDiv, {
882+
childList: true,
883+
subtree: true
884+
});
847885
}
848886

849887
/**

0 commit comments

Comments
 (0)