Generate and create iframe within a blob URL using postMessage for communication var html h1 hello world h1 gscript console log cookie document cookie console log localStorage var counter 1 domain window location protocol window location host send function window setTimeout function console log iframe says domain window parent postMessage counter window postMessage counter counter 1 window parent postMessage window location host window location host window parent postMessage document location document location window parent postMessage document cookie document cookie window parent postMessage localStorage localStorage send uncomment if you want regular tick updates 2000 send gscript gscript src https cdnjs cloudflare com ajax libs chroma js 1 2 2 chroma min js gscript gscript document body style backgroundColor chroma hsv Math random 360 0 0 4 0 8 css gscript html html replace gscript g script var blob new Blob html type text html var blobUrl URL createObjectURL blob var iframe document createElement iframe document body appendChild iframe iframe sandbox allow scripts iframe src blobUrl console log document cookie iframe contentWindow postMessage hello window addEventListener message function event console log yes event data false console log ready var html h1 hello world h1 gscript window console error window console log function rest window parent is the parent frame that made this window if String rest includes Error String rest includes HTML rest String rest else if typeof rest object rest JSON stringify rest window parent postMessage source iframe id consoleid message String rest Finally applying the console statements to saved instance earlier _log apply console arguments window onerror function e console log e abcdef console log iframe ready gscript gscript src https cdnjs cloudflare com ajax libs chroma js 1 2 2 chroma min js gscript gscript document body style backgroundColor chroma hsv Math random 360 0 0 4 0 8 css gscript var injector let sum 0 for let bb 0 bb 5 bb sum bb console log sum html html replace aaa inject html html replace abcdef g injector html html replace gscript g script var blob new Blob html type text html var blobUrl URL createObjectURL blob var iframe document createElement iframe document body appendChild iframe iframe sandbox allow scripts iframe src blobUrl window addEventListener message function event console log recv String event data message false console log ready Tidy the minimum working example into a small prototype type into textbox and run in a iframe function run let html gscript window console error window console log function rest window parent is the parent frame that made this window if String rest includes Error String rest includes HTML rest String rest else if typeof rest object rest JSON stringify rest window parent postMessage source iframe id consoleid message String rest Finally applying the console statements to saved instance earlier _log apply console arguments window onerror function e console log e gscript gscript abcdef gscript var iframes document querySelectorAll iframe for var i 0 i iframes length i iframes i parentNode removeChild iframes i let testcode document getElementById ta value html html replace abcdef g testcode html html replace gscript g script var blob new Blob html type text html var blobUrl URL createObjectURL blob var iframe document createElement iframe document body appendChild iframe iframe sandbox allow scripts iframe src blobUrl iframe style display none iframe style position absolute end run window addEventListener message function event console log recv String JSON parse event data message false document body style height 200px let ta document createElement textarea document body appendChild ta ta style display block ta style width 100 ta style minHeight 100pt ta id ta let button document createElement button document body appendChild button button innerHTML run button onclick run console log ready
m 360 0 0 4 0 8 css gscript var injector let sum 0 for let bb 0 bb 5 bb sum bb console log sum html html replace aaa inject html html replace abcdef g injector html html replace gscript g script var blob new Blob html type text html var blobUrl URL createObjectURL blob var iframe document createElement iframe document body appendChild iframe iframe sandbox allow scripts iframe src blobUrl window addEventListener message function event console log recv String event data message false console log ready Tidy the minimum working example into a small prototype type into textbox and run in a iframe function run let html gscript window console error window console log function rest window parent is the parent frame that made this window if String rest includes Error String rest includes HTML rest String rest else if typeof rest object rest JSON stringify rest window parent postMessage source iframe id consoleid message String rest Finally applying the console statements to saved instance earlier _log apply console arguments window onerror function e console log e gscript gscript abcdef gscript var iframes document querySelectorAll iframe for var i 0 i iframes length i iframes i parentNode removeChild iframes i let testcode document getElementById ta value html html replace abcdef g testcode html html replace gscript g script var blob new Blob html type text html var blobUrl URL createObjectURL blob var iframe document createElement iframe document body appendChild iframe iframe sandbox allow scripts iframe src blobUrl iframe style display none iframe style position absolute end run window addEventListener message function event console log recv String JSON parse event data message false document body style height 200px let ta document createElement textarea document body appendChild ta ta style display block ta style width 100 ta style minHeight 100pt ta id ta let button document createElement button document body appendChild button button innerHTML run button onclick run console log ready