Skip to content

Commit

Permalink
πŸ“– Warn when using a consent promptUI that contains an iframe (#35986)
Browse files Browse the repository at this point in the history
Because of the rendering cycle, a `promptUI` that contains an `amp-iframe` may cause content flashing.

`promptUISrc` can be used instead and prevent that issue.
  • Loading branch information
alanorozco committed Sep 8, 2021
1 parent 4b0e6be commit 0e619d2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions extensions/amp-consent/0.1/consent-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
whenUpgradedToCustomElement,
} from '#core/dom/amp-element-helpers';
import {setImportantStyles, setStyles, toggle} from '#core/dom/style';
import {isEsm} from '#core/mode';

const TAG = 'amp-consent-ui';
const MINIMUM_INITIAL_HEIGHT = 10;
Expand Down Expand Up @@ -196,6 +197,13 @@ export class ConsentUI {
promptUI
);
}
// Warn of use of <amp-iframe> within a promptUI element.
if (!isEsm() && promptElement.querySelector('amp-iframe')) {
user().error(
TAG,
'`promptUI` element contains an <amp-iframe>. This may cause content flashing when consent is not required. Consider using `promptUISrc` instead. See https://go.amp.dev/c/amp-analytics'
);
}
this.ui_ = dev().assertElement(promptElement);
} else if (promptUISrc) {
// Create an iframe element with the provided src
Expand Down

0 comments on commit 0e619d2

Please sign in to comment.