I tried your suggestion but it does not work, as expected if you consider that what is going to be executed is something that has quotes inside quotes, like
setAttribute("srcdoc","<HTML><div style="some styling here" ></DIV></HTML>");
that line is injected so it has to be
"setAttribute(\"srcdoc\",\"<HTML><div style="some styling here" ></DIV></HTML>\");"
This is what goes inside the function,
but in the log you can see for example:
iframe.setAttribute("srcdoc","<!DOCTYPE html><html><head></head><body><p style="vertical-align:middle;font-size:2em;" >.............
when deep quotes are not escaped how you suggested.
While just applying the escaping of double quotes I get in the log
var%20div%3Ddocument.createelement%28%27div%27%29%3Bdiv.addeventlistener%28%27mouse
the error seems to be anticipated because that string continues and reaches to (the same code position even it belongs to a different IFRAME):
iframe.setattribute%28%22srcdoc%22%2C%22%3C%21doctype%20html%3E%3Chtml%3E%3Chead%3E%3Clink%20href%3D%5C%22https://
that is clearly different
and this change happens just if I escape instead of not escaping as you suggested.