KBM Variables in a Javascript

hi guys.
i have the following Javascript:

type or paste code here
(function () {
  // String für die zusammengesetzten XPaths
  let Xpath = '';

  // Funktion zum Extrahieren des Inhalts eines Elements mit einem bestimmten XPath
  function extractContent(xpath) {
    const xpathResult = document.evaluate(
      xpath,
      document,
      null,
      XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
      null
    );

    // Überprüfe, ob passende Elemente gefunden wurden
    if (xpathResult.snapshotLength > 0) {
      // Greife auf das erste Element in der Liste zu
      const element = xpathResult.snapshotItem(0);

      // Gib den Text des Elements aus und füge ihn zum Ergebnisarray hinzu
      const textContent = element.textContent.trim();

      // Füge den XPath mit einem Komma zum bestehenden String hinzu
      Xpath += (Xpath.length > 0 ? ',' : '') + textContent;
    }
  }

  // Extrahiere den Inhalt der drei angegebenen XPath-Elemente und füge sie zum Ergebnisarray hinzu
  extractContent('//div[@class="headline"]/h1');
  extractContent('//div[@class="job-intro-footer"]//em');
  extractContent('//div[@class="job-content"]');

  // Gib das Ergebnisarray aus, damit Keyboard Maestro darauf zugreifen kann
  return Xpath;
})();

Is it possible to define a KBM Variable 'Xpath'=//div[@class="headline"]/h1',//div[@class="job-intro-footer"]//em,//div[@class="job-content"]

so this Rows can be changed to like:
extractContent('%Variable%Xpath[1]%');
extractContent('%Variable%Xpath[2]%');
extractContent('%Variable%Xpath[3]%');

Is there any way to do that?

Yes.

You should change your script slightly so it reads a Keyboard Maestro variable. See the Execute a JavaScript in Front Browser action for details about reading the variable.

Then it can return the contents.

Then call the script three times from Keyboard Maestro, setting a variable based on the Xpath indexed entry. You can't process tokens from within a JavaScript in a web browser, so you wont be able to use something like %Variable%Xpath[1]% in the JavaScript.

Alternatively, you could place the three values into three Keyboard Maestro variables, and then the script to extract each of them.