BigJk / snd

Sales & Dungeons — Thermal Printer as D&D / TTRPG Utility
https://sales-and-dungeons.app/
MIT License
500 stars 17 forks source link

Infinite loops in Javascript that is contained in Templates #19

Closed BigJk closed 1 year ago

BigJk commented 1 year ago

Opening this issue to keep track of possible solutions. Currently there is a problem that if a template contains javascript that blocks infinitely the whole application will freeze and needs a restart. Examples would be:

<script>
while(true) {}
// or
for (let i = 0; true; i++) { }
// or
for (let i = 0; i < 100; i) { }
// and so on...
</script>

Rendered templates will be previewed in iframes and because this iframe is from the same origin it will be run in the same thread as the rest of the applications. That results in the problem when the iframe content blocks the whole application blocks.

Solution 1

Force iframe to be on separate thread. This doesn't seem to work at the moment, as I need the iframe to have the allow-same-origin option which seems to prevent iframes from running in their own thread even if the sandbox option is used.

Solution 2

I tried to switch to the webview tag. This also doesn't seem to be working. In theory the webview sounds perfect, but there is a issue that makes it apparently impossible to directly load arbitrary HTML into it and have the contained scripts run. The HTML will show fine but no scripts are working.

BigJk commented 1 year ago

Finally got the webview tag working after updating astilectron to support newer electron versions.

https://github.com/BigJk/go-astilectron https://github.com/BigJk/astilectron