AutomaApp / automa

A browser extension for automating your browser by connecting blocks
https://www.automa.site
Other
10.73k stars 1.09k forks source link

AutomaSetVariable does fail to work and fetch variables on some of my javascripts. 100% #1681

Closed sparkls0 closed 3 months ago

sparkls0 commented 3 months ago

Hello there, I'm 100% certain that automaSetVariable does fail to fetch variable that are valid in the Javascript.

For example, here is some code below, that does show a working string variable text in the console, but Automa does not add/show the variable transcript.

yet text variable is just a string that is not empty

// Check every second

function checkDivsExist() {
  let divs = document.querySelectorAll('div[class*="transcribe_contents"][data-private]');
  console.log('Checking divs...', divs.length); 

  if (divs.length > 0) {
    clearInterval(checkExistenceInterval); 
    let allTextContent = '';

    divs.forEach(div => {
      allTextContent += div.textContent + '\n\n';
    });

    let text = allTextContent.trim().toString(); 
    console.log(`%c ${text}`, "color: #F9D71C; font-weight: bold;");
    automaSetVariable('transcript2', text);
  }
}

let checkExistenceInterval = setInterval(checkDivsExist, 1000); 

automaNextBlock()```

here is another code that fails to add the variable to Automa : 

function logTextFromLastAssistantMessage() { let conversationTurns = document.querySelectorAll('div[data-testid*="conversation-turn"]');

let assistantMessages = Array.from(conversationTurns).filter(turn => turn.querySelector('div[data-message-author-role="assistant"]'));

let lastMessage = assistantMessages[assistantMessages.length - 2];

if (lastMessage) {
    let textElements = lastMessage.querySelectorAll('p, ul, li, h1, h2, h3, h4, h5, h6');

    let fullText = Array.from(textElements).map(element => element.textContent.trim()).join('\n');

    console.log(fullText);
    automaSetVariable('output', fullText);
    return fullText;
} else {
    console.log('No assistant message found');
    return null;
}

}

logTextFromLastAssistantMessage();

automaNextBlock()