I am creating a chrome extension where on click of the reply button for an email inside of Gmail some text gets pasted inside of the email reply field. I work with an event listener who seems to receive only the initial HTML from the moment on where the reply button gets clicked. I cannot access the reply field which opens up after the reply button gets clicked to insert my email text because if I try to select the div with the class of the div I get an empty object. How can I get the updated HTML and not the initial HTML?
I've tried to use timeouts to wait till the site refreshes and different query selectors.
background.js
console.log("background.js loaded");
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
console.log("message received in background.js");
if (request.type == "click_event") {
console.log("click event captured in current webpage");
}
});
content.js (here the problem occurs)
document.addEventListener("click", (event) => {
if (event.target.innerText == "Reply") {
console.log("reply clicked");
//text from previous email
const element = document.querySelector(".a3s.aiL");
const textContent = element.textContent;
console.log(textContent);
//trying to get the email input field but I get only an empty object back
const insertField = document.querySelectorAll(".a07");
chrome.runtime.sendMessage({
type: "click_event",
});
}
});