markdown-viewer icon indicating copy to clipboard operation
markdown-viewer copied to clipboard

Inline (or included) JavaScript execution by Chrome

Open jbunds opened this issue 1 year ago • 1 comments
trafficstars

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?

jbunds avatar Mar 15 '24 20:03 jbunds

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.

simov avatar Mar 15 '24 21:03 simov

In the 'Markdown Viewer' plugin, the code defined in the <script> block does not work.

However, JavaScript code manually initiated after the page loads is executed, e.g.:

# Title

<label>
<input type="checkbox" onchange="
  if (this.checked) {
    alert('There can be many lines here, but there can not be an empty line or double quotes.')
  };
"> Description </label>

## Chapter

andrzejQ avatar Aug 18 '25 15:08 andrzejQ