"Value cannot be null. Parameter name: html" error when clicking "Insert an external link into the text field" in Experience Editor


Description

In the Experience Editor, clicking the default button "Insert an external link into the text field" on the ribbon of a Rich Text field might fail with an unhandled exception.

The following error can be found in the log records:

Exception: System.ArgumentNullException
Message: Value cannot be null.
Parameter name: html
Source: Sitecore.Kernel
at Sitecore.Diagnostics.Assert.ArgumentNotNull(Object argument, String argumentName)
at Sitecore.ExperienceEditor.Web.LinkConverter.LinkConverter.ConvertHtmlToXmlLink(String html)
at Sitecore.Shell.Applications.WebEdit.Commands.InsertExternalLink.Run(ClientPipelineArgs args)

Note: the same issue occurs when trying to add an external link in the message Edit Body dialog in Email Experience Manager (EXM).

Solution

To resolve the issue, consider upgrading the Sitecore XP instance to Sitecore XP 9.3 or later.

Alternatively, consider the following solution:

  1. Open the \sitecore\shell\Applications\Page Modes\ChromeTypes\FieldChromeType.js file.
  2. Make the following changes in the code (in bold):
    Sitecore.PageModes.PageEditor.postRequest(
    message +
    '(itemid=' +
    itemid +
    ',language=' +
    language +
    ',version=' +
    version +
    ',fieldid=' +
    fieldid +
    ',controlid=' +
    controlid +
    (message === "webedit:insertexternallink" ? ',selection=' + this.getSelectedHtml() : "") +
    ',webeditparams=' +
    parameters +
    ')',
  3. Clean the browser's cache.