1

I'm trying to create a chrome extension which can fill in a form on a certain website.

On the website, you need to give your email address, and this gets checked on the database, whether the account exists or not, and it will show the password field whenever the account exists.

Now, with the chrome extension, I'm trying to make it so that the email address gets filled in automatically, and I'm doing this with jQuery:

$('#emailAddress').val('email@example.com').change();

But this doesn't trigger the event on the page. After some searching, I found that the event happens with knockoutjs, and after some more searching, I found that making jQuery trigger a knockoutjs event is possible when you load jQuery before knockout.

Would anyone know how I would be able to achieve this in a chrome extension?

Thanks in advance.

Rompetomp
  • 51
  • 1
  • 4
  • Did you try this syntax $( "#emailAddress" ).trigger( "change" ); to trigger the event ? – Miiite Apr 30 '14 at 15:18
  • Do you have access to your email observable? on your email observable you can call valueHasMutated() method. email.valueHasMutated() - this will invoke all of the subscribers. – milagvoniduak Apr 30 '14 at 16:27
  • trigger("change") doesn't work. – Rompetomp May 02 '14 at 12:42
  • How would you get access to an observable from a chrome extension? – Rompetomp May 02 '14 at 12:43
  • You can use `ko.dataFor(element)` to retrieve the data that is bound to element from outside. See http://knockoutjs.com/documentation/unobtrusive-event-handling.html for more information. – janfoeh May 04 '14 at 09:18

1 Answers1

0

Credits to the second answer in this question (Triggering a click event from content script - chrome extension)

jQuery's click trigger function does not trigger a non-jQuery DOM click listener.

We must dispatch an event on the javascript object as follows:

$(css_selector)[0].dispatchEvent(new MouseEvent("click"))

Cheers !!

Community
  • 1
  • 1