mScript(scriptText) {
      // Remove the final part of the script which is not relevant.
      scriptText = scriptText.replace(/DOCS_modelChunkLoadStart =.*/, '');

      // Rename the object to a more internal name.
      scriptText = scriptText.replace('DOCS_modelChunk', 'EdgeTextChunkObject');

      // Add a return statement to the script. We're basically constructing a
      // function that returns the text from the script. For instance, the final
      // function will look like this -
      // function () {
      //   EdgeTextChunkObject = [{'s': 'Hello World'}];
      //   if (EdgeTextChunkObject.length === 0) {
      //     return '';
      //   }
      //
      //   if (!EdgeTextChunkObject[0].hasOwnProperty('s')) {
      //     return '';
      //   }
      //
      //   return EdgeTextChunkObject[0]['s'];
      // }
      scriptText += `;
        if (EdgeTextChunkObject.length === 0) {
          return '';
        }

        if (!EdgeTextChunkObject[0].hasOwnProperty('s')) {
          return '';
        }

        return EdgeTextChunkObject[0]['s'];
      `;

      const scriptExtractTextFunction = new Function(scriptText);
      return scriptExtractTextFunction();
    }

    // Get all script tags in the page.
    const scripts = [...document.querySelectorAll('script')];
    if (scripts) {
      const chunks = scripts
        .map((script) => script.innerText)
        .filter(
          (scrTxt) => scrTxt && scrTxt.trim().startsWith("DOCS_modelChunk =")
        )
        .map((scriptText) => extractTextFromScript(scriptText.trim()))
        .filter((extractedText) => extractedText.length > 0);

      if (chunks.length > 0) {
        return chunks.join(' ');
      } else {
        // Fallback to the body text.
        return document.body?.innerText || '';
      }
    } else {
      return '';
    }
  })();