Answer the question
In order to leave comments, you need to log in
What to do if the content script from the extension does not work as it should?
The content script of my extension for the Google Chrome browser looks like this:
document.getElementById("top_audio_player").dispatchEvent(new MouseEvent("mousedown"));
document.getElementById("top_audio_player").dispatchEvent(new MouseEvent("mousedown"));
console.log(document.getElementsByClassName("audio_page_player_title_performer")[0].childNodes[0].innerHTML);
Answer the question
In order to leave comments, you need to log in
It looks like your third line is called before the handler from the first two has completed.
Set the delay to half a second.
document.getElementById("top_audio_player").dispatchEvent(new MouseEvent("mousedown"));
document.getElementById("top_audio_player").dispatchEvent(new MouseEvent("mousedown"));
setTimeout(() => {
console.log(document.getElementsByClassName("audio_page_player_title_performer")[0].childNodes[0].innerHTML);
}, 500);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question