How to interact with elements of the tab opened with GM_openInTab

596 Views Asked by At

I am opening a new tab using GM_openInTab inside my tampermonkey script, but I am not able to interact with the elements of this new tab using my code.

I simply want to click a button in the newly opened tab as soon as it opens and close it instantly.

Thanks in advance!

1

There are 1 best solutions below

0
On

You have to run your script on the URL of the new tab you are opening as well (add an additional @include on top), you could make a distinction at the beginning of the script, like this:

if (location.href == oldurl){
  //open new tab
} else if (location.href == newurl){
  //click button, close
}