I create an extension to automate actions on the page. Cannot simulate keyup.

The code is as follows:

$("span").click(function () { $('.basket-item-amount').val('1000'); $('.basket-item-amount').trigger('keyup'); $(".flat_button.basket-dobet").click(); }); 

It is absolutely identical for both Chrome and Firefox. The console also runs as it should, but when I run as an extension, the trigger ('keyup') does not work.

What are the options to get out of this situation? Actually, site scripts are tied up, and only keyup calls them.

  • And where do you put this code? In order for it to pass a handler to the page, it needs to be inserted into contentscript, in theory it should work. If it is in the content, then maybe it loads faster than the span, and the click needs to be hung on the document - Artem Gorlachev

1 answer 1

Try using a KeyboardEvent object; Example:

 var ev = new KeyboardEvent("keyup",{key:"f",code:"KeyF",target:input}); input.dispatchEvent(ev); 
  • The code is executed, but does not bring any result. - Andrew
  • Are you sure that the event causes a keyup, not a keydown or input? - Dmytryk
  • Of course, specially checked it in the source code. - Andrew
  • Changed the answer. - Dmytryk