simov / markdown-viewer

Markdown Viewer / Browser Extension
MIT License
1.01k stars 131 forks source link

Inline (or included) JavaScript execution by Chrome #232

Open jbunds opened 3 months ago

jbunds commented 3 months ago

I realize that I am arguably pushing against the boundaries Markdown's design philosophy in terms of reasonable use cases, but is it possible to define some simple JavaScript like the following within a *.md document rendered by the Markdown Viewer extension for Google Chrome:

<script type="text/javascript">
  alert("hello");
</script>

I can see the inline JavaScript is being passed onto Chrome from within the "Elements" tag in Chrome's inspection console, but Chrome does not appear to actually execute it, and I can't figure out why.

Is there perhaps a configuration I missed which will allow Chrome to actually execute the inline (or included) JavaScript?

simov commented 3 months ago

I think it is because of the underlying framework that I use https://mithril.js.org/trust.html#scripts-that-do-not-run or rather, the fact that it is the default behavior in the browser. Your script tag is being added dynamically after the page has been rendered and therefore the browser ignores it.