0

I have made an extension for chrome. It's purpose is to read data from popup window, store that data to database and then close the popup window. Everything is working great but I cannot close the popup window.

My plan is to close the popup window with this code:

$('a.tv-dialog-title-close').trigger('click'); 

if I type that in to chrome console it closes the popup window nicely, but when I use that exact code in my extension then popup window wont close and I get no errors (weird). Everything else is working just as planned but this one line of code is not working. Anyone, any thoughts ?

Thank you

EDIT:

Got it working with this:

var scriptNode          = document.createElement ('script');
scriptNode.textContent  = "$('a.tv-dialog-title-close').trigger('click');";
document.body.appendChild (scriptNode); 

Thank you Xan

user3647376
  • 91
  • 2
  • 12

1 Answers1

1

When you execute this code inside the console, you execute it in the page's context.

When you execute this as a content script, it's executed in the isolated context and cannot reach page-defined handlers. There is no error, as it's a valid call and triggers (non-existing) handlers registered by you.

Look into injecting your code into the page's context, as described here.

Community
  • 1
  • 1
Xan
  • 74,770
  • 16
  • 179
  • 206