I am creating an extension in which launch should be simulated with a space in the contenteditable div, where the user enters the message (statuses) in Google Plus.
If you open plus.google.com and you click on the div where you should enter the message, you will understand that when you enter the link inside the message and press {space} you will notice that Google receives the name, image and description of this link. I’ve been trying to simulate a space bar press for 3 days. I can already imitate the manipulation of form elements, I can simulate click () in the submit button, but I still can not simulate a spacebar press.
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.cB").children().eq(1).get(0).dispatchEvent(e);
Thank you very much.
EDIT:
I don’t know if the test will help you, but I advise you to 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.cB").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.cB").children().eq(1).get(0).dispatchEvent(e);
For some reason, this does not cause an informatino link lookup. But if you just click on the div and press the spacebar, you will see that Google is receiving information about this link.