Skip to content

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

@clemdavies

Description

@clemdavies

⚠️ This issue respects the following points: ⚠️

  • This is a bug. Not a question or feature request.
  • The topic is not already reported at Issues. (I've searched it).
  • Markor is up to date. See Releases for the latest version. Updates are available from F-Droid and GitHub.
  • The bug is still present in the latest development version (git master). (Please download and try the test version of Markor, named Marder. Don't worry; Markor and Marder appear as completely separate applications. You can install both side-by-side, and Markor settings are not touched. In case the issue is resolved there, you don't need to create a bug report. The change will be part of the next Markor update.)

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>
  1. create a new empty .md file
  2. edit the file and insert some text to generate at least one <p> tag in the view mode.
  3. view the .md file in Markor/Marder
  4. note that the injected snippet does not execute. no red text.
  5. 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>
  1. view the .md file again in Markor/Marder
  2. 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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions