gsantner / markor

Text editor - Notes & ToDo (for Android) - Markdown, todo.txt, plaintext, math, ..
https://github.com/gsantner/markor/discussions/2269
Other
3.85k stars 369 forks source link

v2.125: Inject-Head not triggering - Undefined reference inside onPageLoaded_markor_private prevents execution of user injected definition onPageLoaded #2380

Closed clemdavies closed 3 months ago

clemdavies commented 3 months ago

⚠️ This issue respects the following points: ⚠️

Description

I was debugging my own injected script not working anymore. I found what I believe is a bug that will break all injected scripts that use onPageLoaded() to execute their code.

Here is a snippet of the generated html file which has the first script block being my injection through the app settings, the rest is generated by the app itself.

<script type="text/javascript">
function onPageLoaded(){
    document.querySelectorAll("p").forEach(el => el.setAttribute("style","color:red"));
}
</script><script> function onPageLoaded_markor_private() {
wrapCodeBlockWords();
onPageLoaded(); }
</script></head>
<body class='format-markdown fileext-md' onload='onPageLoaded_markor_private();'>

The problem is that there is no function definition for wrapCodeBlockWords anywhere in the file, so this appears to break execution resulting in onPageLoaded never being called.

By injecting my own definition for wrapCodeBlockWords i can fix the execution cycle and ensure that onPageLoaded is called. see steps to reproduce

Steps to reproduce

  1. insert a simple js snippet that should run in settings -> view mode -> inject head ie:

    <script type="text/javascript">
    function onPageLoaded(){
    document.querySelectorAll("p").forEach(el => el.setAttribute("style","color:red"));
    }
    </script>
  2. create a new empty .md file

  3. edit the file and insert some text to generate at least one <p> tag in the view mode.

  4. view the .md file in Markor/Marder

  5. note that the injected snippet does not execute. no red text.

  6. Edit the above injected snippet to the following:

    <script type="text/javascript">
    function onPageLoaded(){
    document.querySelectorAll("p").forEach(el => el.setAttribute("style","color:red"));
    }
    function wrapCodeBlockWords(){}
    </script>
  7. view the .md file again in Markor/Marder

  8. the injected snippet should execute

note: I included the hack/workaround that fixes the execution above as I wanted to be sure that resolving the undefined reference would fix the issue purely inside the app. In order to find it in the first place I used the share as html to export what I assume is the same html file being viewed in the app. However I cannot guarantee that the view mode is rendering the same exported html, or that the export process is adding or removing anything. But this method of exporting could also be used to investigate the issue.

Information

Android version: 14 Device: samsung galaxy a15 5g Markor App Version: 2.12.4 Marder App Version: 2.12.5-2245

Source

F-Droid

Format / File type

Not specific

Additional info / Log

I did a quick check on other file types that can be created within the app:
1. create an empty file of X type in app
2. share as html
3. inspect html output for undefined reference to wrapCodeBlockWords

Affected:
Markdown
wikitext/zim
CSV

Unaffected:
plain
todo
asciidoc
orgmode
gsantner commented 3 months ago

Thanks for checking in detail, seems some recent change related to js vendored stuff is related ( @guanglinn )

gsantner commented 3 months ago

Probably also a duplicate to what actually was meant with #2365

guanglinn commented 3 months ago

I will check it tomorrow, believe this issue will be solved soon. @gsantner

gsantner commented 3 months ago

Thanks, feel free to if you want to. There is no implication that you or somebody else specifically should do something.

I can check after holiday too, but guess theres a good chance somebody else took a look by that 😃