0

I have this script running at the end of the document loading:

$(function () {
    $("input").keydown();   
});

The script is in a chrome-extension that run on each page the user loads and doesn't work (i.e. on twitter website). However, if the same script is executed on the chrome javascript console it work perfectly.

Do you have any clue about how to trigger this event from the script?

  • does you call it from content.js ? – Alex Kneller Oct 31 '13 at 18:53
  • Well, I have a file called search.js and I put the name of the file on the manifest file to run at document end. The link and the file work fine and if I put some other function inside the $(function(){}); they work perfectly. Also the jQuery script (1.10.2) is called on document end before the search.js script – user2942689 Oct 31 '13 at 22:08
  • DOM can be manipulated only from content scripts, did you put search.js in to content scripts in manifest ?http://stackoverflow.com/questions/10066100/google-chrome-extension-manipulate-dom-of-open-or-current-tab – Alex Kneller Nov 01 '13 at 10:36
  • Yes, the script works fine. I also have other scripts inside the function I wrote that add elements to the page and they are correctly inserted. The problem is only when trying to triggering a keydown. – user2942689 Nov 01 '13 at 15:47
  • 1
    Found this hope this helps. http://stackoverflow.com/questions/17152932/chrome-extension-how-to-send-keydown-event-to-pages-input – Alex Kneller Nov 02 '13 at 05:22

1 Answers1

0

I fixed the code adding this line and now the keydown even is triggered correctly

var event = new KeyboardEvent('keydown');
document.querySelector('[id="inputid"]').dispatchEvent(event);