I am creating an extension where I must simulate a spacebar keydown on the contenteditable div where the user type the message (statuses) in the Google Plus.
If you open plus.google.com and you click on the div where you must type the message you will realize that when you type a link inside the message and you press {spacebar} you will notice that Google retrieves title, image and description of that link. I am 3 days trying to simulate the spacebar keydown. I can already simulate mouseover over the elements of the form, I can simulate click() in the send button but I still can't simulate the spacebar keydown.
So far my best code is:
var e = new KeyboardEvent("keydown", {bubbles : true, cancelable : true, key : " ", char : " ", shiftKey : false, keyCode: 32, which: 32, view: window});
//I need to delete the e.keyCode and e.which cause Chrome sets it as a readonly but for some reason if you delete it and assign a new value Chrome accepts (I am very sure this is a serious bug that I discovered in Chrome and that I already reported yesterday in theis bug tracker)
delete e.keyCode;
Object.defineProperty(e, "keyCode", {"value" : 32});
delete e.which;
Object.defineProperty(e, "which", {"value" : 32});
$(".Cla").find(".be.c-B").children().eq(1).get(0).dispatchEvent(e);
Thank you so much.
EDIT:
I do not know if it helps you make a test but I advise you do this:
opened_window = window.open("http://plus.google.com");
after that click in the div to expand it and after that just run this code:
$(".Cla").find(".be.c-B").children().eq(1).html("The site stackoverflow.com is amazing");
var e = new KeyboardEvent("keydown", {bubbles : true, cancelable : true, key : " ", char : " ", shiftKey : false, keyCode: 32, which: 32, view: window});
delete e.keyCode;
Object.defineProperty(e, "keyCode", {"value" : 32});
delete e.which;
Object.defineProperty(e, "which", {"value" : 32});
$(".Cla").find(".be.c-B").children().eq(1).get(0).dispatchEvent(e);
For some reason this does not trigger the retrieval of link informatino. But if you just click in the div and press spacebar you will see that Google retrieves information about that link.