I have a test web page that alerts if i hit a key in it's input field:
<!doctype html>
<html>
<head>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script>
$( document ).ready( function() {
$( '#foo' ).keydown( function() { alert( "debug" ); } );
});
</script>
</head>
<body>
<input id='foo' type='type'/>
</body>
</html>
And i have this chrome extension that modifies input text and fires keydown event:
$( document ).ready( function() {
window.setTimeout( function() {
$( '#foo' ).val( "foo" );
$( '#foo' ).keydown();
}, 2000 );
});
If i install extension, after 2 seconds (as expected) text is modified - but alert is not displayed, so i can suggest that keydown
event is not passed from extension sandbox into page javascript handler. Is it possible to modify my code somehow so extension can emulate keydown that javascript on the page can see? I'm automating a third-party website via chrome extension, and one of the inputs requires keyup
to detect value change (the page i'm automating is written badly - but i don't have any control other it's source code).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…