Anushka Gupta
Anushka Gupta

Reputation: 21

How to interact with elements of the tab opened with GM_openInTab

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!

Upvotes: 2

Views: 798

Answers (1)

CennoxX
CennoxX

Reputation: 808

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
}

Upvotes: 0

Related Questions