I am writing a chrome extension that accesses the active tab page and manipulates the DOM by injecting some code with a content script. However, I am having no luck when it comes to firing event handlers that should be registered by the active tab page's own JavaScript.
For example, on the web page itself there is a save button that saves all the form data when clicked. On my chrome extension, I have a button that, when clicked, sends a message to a content script. The content script then has a line of code to fire the web page save button's event handler to save the form data, but it does not work, even when I tell it to do so using $('#btnSave').click()
.
Another example, I have a button on my chrome extension that when clicked, selects a value from the drop down list located on the web page. It selects the value fine, but it does not fire the change event for the drop down list, even when I explicitly tell it to do so using $('#ddl').change()
.
Both commands fire the respective controls events fine when I type them in the console, but not when using them in my content script. So how do I access the web page's event handlers from my content script?
P.S. Have also tried invoking event handler using .trigger(event)
, .triggerHandler(event)
, .change()
for select, and my code is wrapped inside $(document).ready()
.