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>
  • 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. – wOxxOm May 03 '20 at 08:44
  • Thanks for getting back! Any advice on how to save the DOM elements? – bleepbloopbleep May 03 '20 at 15:23
  • [How to generate unique css selector for DOM element?](https://stackoverflow.com/q/8588301) – wOxxOm May 03 '20 at 15:34

0 Answers0