0

I'm currently developing a Twitter browser extension, and I've encountered an issue with injecting AI-generated text, obtained from an API, into Twitter's tweet input field. Although the injection process seems successful, the text doesn't persist properly on Twitter's servers. Additionally, even after removing or editing the injected text from the input field, it remains visible and superimposed on the interface.enter image description here On removing all the injected text from the input field, the "Post" buttom dims out and it looks like that:

enter image description here

Here's the code I used:

function setTwitterInputText(aiGeneratedText: string) {
  const inputField = document.querySelector(
    '[class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr"]'
  );

  if (inputField) {
    const dataOffsetKey = inputField.getAttribute('data-offset-key');
    
    const span = `<span data-offset-key=${dataOffsetKey}>
                     <span data-text="true">
                        ${aiGeneratedText}
                     </span>
                  </span>`;
    inputField.innerHTML = span;
    (inputField as HTMLInputElement | HTMLTextAreaElement).click();
    inputField.dispatchEvent(
      new Event('input', { bubbles: true, cancelable: true })
    );
  }
}

I'm seeking guidance on how to ensure that the injected text properly persists on Twitter's servers.

2
  • Try the deprecated document.execCommand, example. Commented Apr 8, 2024 at 19:50
  • Didn't work, I tried that. Commented Apr 8, 2024 at 20:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.