Skip to content
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

Intent to Implement: <amp-wordpress-embed> Embedding WordPress Posts #18378

Closed
amedina opened this issue Sep 26, 2018 · 4 comments · Fixed by #34948
Closed

Intent to Implement: <amp-wordpress-embed> Embedding WordPress Posts #18378

amedina opened this issue Sep 26, 2018 · 4 comments · Fixed by #34948
Labels
INTENT TO IMPLEMENT Proposes implementation of a significant new feature. https://bit.ly/amp-contribute-code Type: Feature Request WG: bento WG: components
Milestone

Comments

@amedina
Copy link
Member

amedina commented Sep 26, 2018

What's the issue?

Embedding WordPress posts in AMP WordPress content does not work. The issue described here has three parts.

iframe Resizing

WordPress post embeds are designed to securely render WordPress post excerpts in iframes that size themselves to the appropriate dimensions. This is achieved by sending a height message from the wp-embed-template.js script running in the embed template. The WordPress site hosting the embed includes the file wp-embed.js, which receives this height message and resizes the iframe accordingly.

AMP allows the inclusion of iframes with specific attributes, and a specific way to communicate resizing to the host. But this way does not work with the embed mechanism of WordPress because the message passed by the WordPress embed does not correspond to the message sent by the AMP iframe.

Same-origin embeds

The second part of the issue is that it is not possible to add WordPress embeds with the same origin (i.e. on the same site) since same origin iframes are not allowed in AMP if they also need to run scripts, which they do in order to resize properly.

Navigation

The third part of the problem arises when clicking on links inside the embedded iframe. In WordPress, all clicks on links are intercepted and the associated URL is sent in a message to the parent window. Then, the parent window follows the URL if the host is the same as the host of the URL being embedded. In AMP this approach does not work, even if the amp-iframe contains the allow-popups-to-escape-sandbox and allow-top-navigation-by-user-activation attributes.

Solution

The ideal solution for the embedding of WordPress posts on the same origin would be to avoid the iframe altogether, and just inline the embed content template directly into the host page. To achieve this we would need:

  1. Convert the embed template to AMP.
  2. Scope the CSS to only apply to the embed content.
  3. A way to block all styles from being inherited into the embed content's wrapper element.

This can be achieved by attaching the embed content as a shadow DOM. (The WordPress embed template can be served as an AMP document on the same origin.) However, this is not available for us to do in AMP since it requires a custom script. So there needs to be custom AMP extension for handling WordPress embeds.
For WordPress post embeds that are not on the same origin we can continue to use an iframe but handle the WordPress-specific messages posted from the iframe’d window.

How do we reproduce the issue?

  1. Spin off a WordPress install locally
  2. Install and activate the AMP Plugin for WordPress
  3. Configure the plugin in Paired Mode
  4. Create a post
  5. Add a link to a WordPress post
  6. Switch to the AMP version of the page

What browsers are affected?

All.

Which AMP version is affected?

All.

@dreamofabear dreamofabear added INTENT TO IMPLEMENT Proposes implementation of a significant new feature. https://bit.ly/amp-contribute-code Category: Presentation labels Sep 26, 2018
@dreamofabear
Copy link

/cc @aghassemi

@ampprojectbot
Copy link
Member

This issue seems to be in Pending Triage for awhile. @amedina Please triage this to an appropriate milestone.

@stale
Copy link

stale bot commented Jan 30, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Inactive for one year or more label Jan 30, 2021
@westonruter
Copy link
Member

Still going to work on this, but I'll implement it using Bento APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
INTENT TO IMPLEMENT Proposes implementation of a significant new feature. https://bit.ly/amp-contribute-code Type: Feature Request WG: bento WG: components
Projects
None yet
4 participants