Creative API: page visibility#4021
Conversation
… This includes adding a send-embed-state message to subscribe to these updates.
|
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
| this.embedStateApi_ = new SubscriptionApi( | ||
| this.iframe_, 'send-embed-state', is3p, | ||
| () => this.sendEmbedInfo_(this.baseInstance_.isInViewport())); | ||
| this.embedStateApi_.init(); |
There was a problem hiding this comment.
Looks like we always create than immediately call #init. Is there a reason to separate the two steps?
There was a problem hiding this comment.
I suppose not at the moment, switched it to private and made the constructor call it.
| return; | ||
| } | ||
| // Note that we multicast the update to all interested windows. | ||
| postMessageToWindows( |
There was a problem hiding this comment.
if this method is no more used externally, can be private?
There was a problem hiding this comment.
It will be used though, see #4023 for an example.
| * invoked whenever a new window subscribes. | ||
| */ | ||
| constructor(iframe, type, is3p, requestCallback) { | ||
| this.iframe_ = iframe; |
There was a problem hiding this comment.
Please add annotations to those private members.
|
Some more comments. Looks good in general. |
|
CLAs look good, thanks! |
Adds support for subscribing to embed-state messages (which contain page visibility information) from nested ad iframes (as done previosuly for IntersectionObserver). A new message is added, send-embed-state, used to subscribe to the updates.
The code for handling subscription is refactored out of IntersectionObserver and into a reusable class in iframe-helper.js . I also added a test for subscription to embed-state updates as there did not seem to be any at the moment.
This is the next change in the implementation of #3019, apologies for the delay.