-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
amp-iframe: Add support for message protocols of popular libraries that do resizable iframes #22714
Comments
/cc @aghassemi |
We've made changes like this in the past. How does their protocol look like? I couldn't quickly find docs. |
Messages are serialized into a string, prefixed by So a message to update the
|
IMHO, there's no problem to support 1-2 very common resize message formats. But I'd stay away from using the libraries themselves - they often have their own legacy overhead. |
Agreed. Support the protocols but don't incorporate the libraries. |
Weird flex but OK :) I had never heard of Pym. How common is it? |
It's probably the most common solution used by newsroom interactive teams today. It's used at NPR, almost all of our members stations, as well as (I think) the Texas Tribune, St. Louis Post-Dispatch, INN-supported newsrooms, and many others. The message format isn't great, but we don't have the ability to change it now, it was implemented long before I joined the team. We have introduced a new Pym- and AMP-compatible solution called Sidechain, but it isn't in production use yet. And due to the way that we publish graphics to static file hosting, it's not feasible to go back and upgrade them all. |
For context, our CDN distribution for pym.nprapps.org, which is used by us and by other people who embed with this script, sees about 2.5-4M requests per day. That's not the complete story, as many users probably have their own customized version or they bundle it in from the NPM package, but it's not nothing either. |
Pym.js/AMP support has also been requested by a few publications in the Newspack world, including Reveal, The Rivard Report, The Chicago Reporter, and The Hechinger Report. |
INN maintains a plugin that wraps a Pym.js embed in a shortcode or block: https://github.com/INN/pym-shortcode https://wordpress.org/plugins/pym-shortcode/ If there's something we can do to make that work better with the WordPress AMP plugin, please chime in on the Pym.js Embeds plugin's AMP support issue: Automattic/pym-shortcode#59 (and if there's stuff that needs to be done to make the plugin compatible with Newspack, we'd like to know so we can get that implemented, too.) |
Ideally, sender would be updated to send both this and other formats. if that is infeasible, I think it is fine to add support for commonly used message formats on the receiver end. |
PYM support is something we considered some time ago. Just didn't get to it. One point of disconnect: I don't believe PYM supports the "rejection" signal when we deny resize. That was a bit of a concern. Not an issue for user-gesture-based resizing, but definitely could be an issue for onload. |
@dvoytenko would this be a blocker? Or can we move to add protocol support to make libraries like Pym.js AMP compatible? |
@westonruter No, I don't think it'd be a blocker. We could always follow the same protocol and send "rejection" message as well, in case anyone can react to it. |
@dvoytenko Finally opened a PR: #24917. |
I just listened to @calebcordry's talk just now about an “Sustaining an ever-growing AMP component library” at the AMP Contributors Summit; it got me thinking about whether there should be a separate WordPress embed component (#18378, Instead of listening for All that to say, the logic needed for WordPress embeds is similar to Pym.js, though it does have the additional facility for navigation. Does this make WordPress embeds warrant having a separate extension? |
@westonruter I think we should view pym support and the amp-wordpress-embed separately for now, b/c pym is used in non-wordpress embeds as well, right? Otherwise, imho, you should take for amp-wordpress-embed to design review. |
Very excited for #24917 @dvoytenko @westonruter. This could fix hundreds of pages on Axios, thousands if you include the previously mentioned news sites 👏🎉📈 |
…24917) * Add amp-iframe support for Pym.js width and height resize messages Fixes #22714. Pym.js supports the client window sending several types of messages, including: * `height` * `width` * `parentPositionInfo` * `navigateTo` * `scrollToChildPos` The only two messages that seem relevant in an AMP context are width and height, as they map to the embed-size message that AMP is currently looking for. * Use listen event-helper instead of addEventListner directly * Rename unlisten_ to unlistenPym_ * Use this.win instead of window * Indicate event param is non-nullable MessageEvent * Use getData event helper * Warn user about unsupported Pym.js messages * Replace function binding with arrow function to fix JSC_TYPE_MISMATCH * Add test for Pym.js messages for height and width * Add missing tag argument to user().warn() * Use startsWith string helper * Replace array splice with direct references; fix format comment doc * Add missing ID from Pym message * Populate undefined variable sentinel
Many sites use libraries like Pym.js to implement resizable iframes. In AMP,
amp-iframe
has its own message protocol for implementing resizable iframes (#728).Currently, in order to take existing legacy content and put it into AMP pages, they have to be updated to use the the AMP-specific message protocol. It would be great if
amp-iframe
could be made aware of the protocols of popular resizable iframe libraries (like Pym.js), as this would facilitate migration to AMP.This was proposed by @thomaswilburn in nprapps/pym.js#182 (comment):
For more historical context: #495
The text was updated successfully, but these errors were encountered: