1

I am working on a chrome extension when a user and select a button on a webpage (I do this by adding and event.listener and then storing event.target). Then after an action from the user I want to click that button they saved.

I grab the button in the content script and then send a message to the background with the recorded button (event.target).

How that I click the recorded button? Is there a way to do that in the background or do I have to get it to the client?

<button class="ytp-play-button ytp-button" title="Play (k)" aria-label="Play (k)" style=""><svg height="100%" version="1.1" viewBox="0 0 36 36" width="100%"><use class="ytp-svg-shadow" xlink:href="#ytp-id-56"></use><path class="ytp-svg-fill" d="M 12,26 18.5,22 18.5,14 12,10 z M 18.5,22 25,18 25,18 18.5,14 z" id="ytp-id-56"></path></svg></button>
3
  • DOM elements can't be sent via messaging so you need to save it and click it in the content script. Look for an example that uses dispatchEvent, should be trivial to find. Commented May 3, 2020 at 8:44
  • Thanks for getting back! Any advice on how to save the DOM elements? Commented May 3, 2020 at 15:23
  • How to generate unique css selector for DOM element? Commented May 3, 2020 at 15:34

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.