function executeInPage3(code){
let mid = +new Date() + Math.floor(Math.random() * 1000);
function onWindowMessage3(e) {
//**console.log("Message received 3",e)
}
window.addEventListener("message", onWindowMessage3);
code =
"(function(){\n" +
" let fun = " +
code +
";\n" +
" fun(function(result){\n" +
" let msg = {}\n" +
mid +
"\n" +
" msg.result = result\n" +
' window.postMessage(msg, "*")\n' +
" })\n" +
"}())";
let script = document.createElement("script");
script.text = code;
document.head.appendChild(script); <---------- This is where I am getting the error on appending script
}