Fixing Javascript Errors in WordPress SEO

In the last two versions of Yoast’s WordPress SEO plugin there’s been errors in the JavaScript that cause parts of tinymce to not work. The issue is some of the variables are not strings like expected, so when they try to run string methods against them, causing JavaScript to throw a syntax error. The simple fix is to add type checking for lines 189 and 200 of wp-seo-metabox.js. 

if ( !desc || desc.length < 1 ) {
	desc = jQuery("#content").val();
	if(typeof desc == 'string'){
		desc = yst_strip_tags( desc );
	}
	var descsearch = new RegExp( focuskw, 'gim');
	if ( desc.search(descsearch) != -1 ) {
		desc = desc.substr( desc.search(descsearch), wpseo_meta_desc_length );
	} else {
		desc = desc.substr(0, wpseo_meta_desc_length );
	}
	jQuery("#snippet .desc span").css('color','#777777');
}

for (var i in keywords) {
	if(typeof keywords[i] == 'string'){
		var kw			= yst_strip_tags( keywords[i] );
		var urlfocuskw 	= kw.replace(' ','-').toLowerCase();
		focuskwregex 	= new RegExp( '('+kw+')', 'gim');
		urlfocuskwregex = new RegExp( '('+urlfocuskw+')', 'gim' );
		desc 			= desc.replace( focuskwregex, ''+"$1"+'' );
		title 			= title.replace( focuskwregex, ''+"$1"+'' );
		url 			= url.replace( urlfocuskwregex, ''+"$1"+'' );
	}
}

I tried to implement this fix, because the Yoast SEO plugin is breaking my tinyMCE (removing all the buttons on the Visual editor). The code seems to have changed completely, though – I can’t find this part of it in the file you specify.

I can’t rememebr what version this was for. Sadly I forgot to keep track. I know they fixed the issue in one of their later updates, so if you can update I would do that.