Magento Admin Editor – “Opener is null” Issue with Inserting Images/Files

While working on a Magento EE 1.12 site, an issue came up that affect mostly Firefox and Chrome, where anytime we would try to Insert File via the Magento Media Manager, nothing would happen. Investigating this lead to an error: TypeError: opener is null in browser.js. Obviously this is a huge issue, and was able to come up with a quick fix:

This particular file uses the name for the variable “opener” multiple times, which lead me to finding that opener is NOT set in specific situations. Simply renaming the opener variable to something else does the trick, within the getTargetElement() function.

Around line 228 we have:

getTargetElement: function() {
	if (typeof(tinyMCE) != 'undefined' && tinyMCE.get(this.targetElementId)) {
		if ((opener = this.getMediaBrowserOpener())) {
			var targetElementId = tinyMceEditors.get(this.targetElementId).getMediaBrowserTargetElementId();
			return opener.document.getElementById(targetElementId);
		} else {
			return null;
		}
	} else {
		return document.getElementById(this.targetElementId);
	}
},

Change this to:

getTargetElement: function() {
	if (typeof(tinyMCE) != 'undefined' && tinyMCE.get(this.targetElementId)) {
		if ((notOpener = this.getMediaBrowserOpener())) {
			var targetElementId = tinyMceEditors.get(this.targetElementId).getMediaBrowserTargetElementId();
			return notOpener.document.getElementById(targetElementId);
		} else {
			return null;
		}
	} else {
		return document.getElementById(this.targetElementId);
	}
},

After changing this we have had no issues uploading and swapping/inserting images and files within Magento’s CMS or Static Block editors!

Posted in Javascript, Magento, Magento Enterprise, Magento Fixes
  • Vishal

    Hi Mate,

    Sorry! It is giving me another issue on editor in Magento2.
    I am using custom module but now getting different error in console.
    TypeError: targetEl is null

    Please help.

    Thanks
    Vishal Sanwar

  • You have done a great job by sharing this informative post.Appreciate your formulating an exceptionally decent article.

  • Jaimin

    Thanks it works..

  • Brad Taylor really good information sharing helping me .. thanks …

  • Saved my day.

  • Ugo

    Hey man tnx! U made my day!

  • NB

    Thanks for this… Its even working with CE version too

    • Thanks for letting me know – glad to hear it’s similar across versions!

  • magento developer

    thnks lot…its nice..

  • Thanks a lot for helping us and solved our doubt. Keep sharing. Great work.

    • Glad to hear! Thanks for the comment, always working on new ideas and posts 🙂

  • Vitaly Kudrinsky

    Thank you very much!!!!

  • Same here, thanks very much.

  • Ryan

    Thanks, we just ran into the same bug. Very helpful.