9

There is an error at my console showing Uncaught TypeError: Cannot read property 'secret' of null at a.wp.receiveEmbedMessage (wp-embed.min.js?x59911:1)

Is there a way to fix this?

2
  • 3
    We have the same error, which only showed up recently. From testing on our end, and searching online, it appears to be an issue with Google ReCaptcha. Do you use that on your site? Aug 27, 2018 at 13:37
  • interaction effect between the recaptcha and the core's wp-embed.js
    – Julix
    Sep 13, 2018 at 21:54

5 Answers 5

8

Issue is with Wordpress wp-embed.js . Change following following code/

if ( ! ( data.secret || data.message || data.value ) ) {

to

if ( ! data || ! ( data.secret || data.message || data.value ) ) {

On line 32. It should solve the issue. Refrence : https://core.trac.wordpress.org/ticket/44832

4
  • I have made the changes. However, for some reason, the old version of js is still loading. Any idea? Sep 6, 2018 at 11:09
  • Please check whether you have installed caching/speed optimization plugins on WordPress.
    – webmatrix
    Sep 6, 2018 at 12:13
  • You are correct. It was an issue with the caching. However, there were no caching plugins used for WordPress. Godaddy WordPress managed hosting has this issue and they are still working to fix the same. Sep 7, 2018 at 4:04
  • It's not caching, it's the minified js file that's actually being used. See my answer.
    – Julix
    Sep 13, 2018 at 22:08
6

The issue ticket (also linked by Webmatrix) suggests the following code for wp-embed.js (starting line 31).

if ( data && ! ( data.secret || data.message || data.value ) ) {
    return;
}

But changing that won't matter, since the wp-embed.min.js file is the one actually used. - And since it's all on one line, it's a little harder to find the right place.

Search for the string d.secret|| to find the right part and then replace that condition check with if(d && !(d.secret||d.message||d.value)).

I had the same issue and doing this fixed it for me, while webmatrix's code (minified) if ( !d||!(d.secret||d.message||d.value) ) didn't work for my problem.

This suggests that in my case data is in fact being passed, it just doesn't have the value that I want. Maybe there's also a problem of sometimes no data being passed at all in which case you should still add his !data || at the very beginning of my conditional, like so: if(!d||d && !(d.secret||d.message||d.value)).


Note

However, note you shouldn't be editing core files usually - because it could vanish on the next update - in this situation though, the next update is very likely to contain the same or a better fix, so if it's overwritten it shouldn't matter.

5

It seems like the fix for that problem depends on your WordPress version. In 4.9.8 the problematic snippet in /wp-includes/js/wp-embed.min.js looks like this:

var d=c.data;if(d.secret||d.message||d.value)if(!/[^a-zA-Z0-9]/.test(d.secret)){...}

There is no exit condition in this case, but rather a continuation condition. The following code will be executed if the previous conditions are fulfilled. Thus you need to check if the conditions are met, instead of being not met.

This worked for me:

var d=c.data;if(d&&(d.secret||d.message||d.value))...

It checks first if d is valid (not null) and then goes on to check if any of the following conditions are met.

Make sure to reload the page without the cache after uploading the fix. Ctrl+F5 for Chrome and Firefox on Windows or Command+Shift+R for Chrome and Firefox on Mac.

0
1

Modifying directly the wp-embed.min.js and it works perfectly and the console error dissapears.

Particulary, in the minified code I change this piece of code

 > if(d.secret||d.message||d.value)

for this piece of code

 > if(!d||!(d.secret||d.message||d.value))return;

(be carefull, the first one hasn’t got semicolon and the second one has got semicolon)

However, I do not recommend changing the WP core code in any way.

-1

Disable Embeds in WordPress With Code

You can add the following to your WordPress theme’s functions.php file.

function disable_embeds_code_init() {

 // Remove the REST API endpoint.
 remove_action( 'rest_api_init', 'wp_oembed_register_route' );

 // Turn off oEmbed auto discovery.
 add_filter( 'embed_oembed_discover', '__return_false' );

 // Don't filter oEmbed results.
 remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );

 // Remove oEmbed discovery links.
 remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );

 // Remove oEmbed-specific JavaScript from the front-end and back-end.
 remove_action( 'wp_head', 'wp_oembed_add_host_js' );
 add_filter( 'tiny_mce_plugins', 'disable_embeds_tiny_mce_plugin' );

 // Remove all embeds rewrite rules.
 add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );

 // Remove filter of the oEmbed result before any HTTP requests are made.
 remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
}

add_action( 'init', 'disable_embeds_code_init', 9999 );

function disable_embeds_tiny_mce_plugin($plugins) {
    return array_diff($plugins, array('wpembed'));
}

function disable_embeds_rewrites($rules) {
    foreach($rules as $rule => $rewrite) {
        if(false !== strpos($rewrite, 'embed=true')) {
            unset($rules[$rule]);
        }
    }
    return $rules;
}

Or you could also use the wp_dequeue_script function.

function my_deregister_scripts(){
 wp_dequeue_script( 'wp-embed' );
}
add_action( 'wp_footer', 'my_deregister_scripts' );

Try to use this code. It's Working...

Thanks !

1
  • 2
    Turning off all WordPress embed capabilities because of a javascript error seems like an over correction. Isn't it better to determine the reason for the error and fix that, instead? Aug 27, 2018 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.