Make WordPress Core

Opened 3 years ago

Last modified 9 days ago

#44306 new defect (bug)

wp-embed-template.js Sends a message earlier than the wp-embed.js listener will be installed

Reported by: Cawa-93 Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.9.6
Component: Embeds Keywords:
Focuses: javascript Cc:


I use google chrome v67.0.3396.62

In the content of the page is inserted a link to another page of the same site.

This link is replaced by the iframe.
However, this frame is loaded before downloading the listener's wp-embed. Because of this, the frame does not update its height and does not replace the blockquote element

I enabled debugging and added the output to the console to monitor the execution order. Here is the result:

14:36:01.651 (index):758 sendEmbedMessage(height, 348)
14:36:02.134 wp-embed.js?ver=4.9.6:121 addEventListener(message)
14:36:02.588 wp-embed.js?ver=4.9.6:89 onLoad()
14:36:04.889 wp-embed.js?ver=4.9.6:89 onLoad()

The widget only appears if you resize the page after loading the page. Here is the log

14:36:08.091 (index):758 sendEmbedMessage(height, 250)
14:36:08.092 wp-embed.js?ver=4.9.6:31  receiveEmbedMessage data: {message: "height", value: 250, secret: "Fr0AAXkEeU"}
14:36:08.240 (index):758 sendEmbedMessage(height, 250)
14:36:08.240 wp-embed.js?ver=4.9.6:31  receiveEmbedMessage data: {message: "height", value: 250, secret: "Fr0AAXkEeU"}

Change History (3)

#1 @Cawa-93
3 years ago

If, however, I pre-register the script in the header and not in the footer, then the frame of the widget is displayed correctly.

function embed_on_head() {
        wp_enqueue_script('wp-embed', includes_url( '/js/wp-embed.min.js' ), array(), false, false);

Here is the log:

14:52:18.132 wp-embed.js?ver=4.9.6:121 addEventListener(message)
14:52:19.536 (index):758 sendEmbedMessage(height, 299)
14:52:19.574 wp-embed.js?ver=4.9.6:31  receiveEmbedMessage data: {message: "height", value: 299, secret: "Fr0AAXkEeU"}
14:52:21.533 wp-embed.js?ver=4.9.6:89 onLoad()
14:52:22.409 (index):758 sendEmbedMessage(height, 299)
14:52:22.510 wp-embed.js?ver=4.9.6:31  receiveEmbedMessage data: {message: "height", value: 299, secret: "Fr0AAXkEeU"}
14:52:23.259 wp-embed.js?ver=4.9.6:89 onLoad()
Last edited 3 years ago by Cawa-93 (previous) (diff)

#2 @westonruter
9 days ago

While I haven't seen this issue myself, I have solution that should prevent the issue from happening.

#3 @swissspidy
9 days ago

  • Milestone changed from Awaiting Review to Future Release
  • Severity changed from major to normal

Copying over from #44632:

To solve the race condition, I think wp-embed-template.js should

  • not send the message on load if the secret is missing
  • send the message as soon as the secret has been added (which means wp-embed.js has been loaded)
Note: See TracTickets for help on using tickets.