openLinkText run outside of a Markdown Editor crashes Obsidian Mobile on Android

Anchors placed outside of a Markdown Editor and without clickHandlers don’t navigate. Therefore one needs to use openLinkText. But in certain mobile environments, clicking these links crashes Obsidian.

Steps to reproduce

(More info can be found in this repro: GitHub - SkepticMystic/obsidian-openLinkText-mobile-bug)

  1. Open a new vault
  2. Install this plugin (probably via BRAT)
  3. Run the “Open Example View” command
  4. Click the links in the view
  • “anchor without clickHandler”
    • Doesn’t do anything, but this is kind of expected
    • Would be nice if we could use regular anchors though
  • “anchor with clickHandler”
    • On Desktop, the note will open
    • On Mobile, Obsidian crashes
  • “div with clickHandler”
    • Works on Desktop
    • Crashes on Mobile

Did you follow the troubleshooting guide? [Y/N]

Y

Expected result

Running openLinkText outside a Markdown Editor, on mobile should navigate to the target note.

Actual result

Obsidian crashes

Environment

It does not work in the following environment:

SYSTEM INFO:
Operating system: android 11
Obsidian version: 1.5.11 (133)
API version: v1.5.11

It works in the following environment:

SYSTEM INFO:
Operating system: ios 17.4.1
Obsidian version: 1.5.12 (134)
API version: v1.5.12


Additional information

This minimal reproduction should be helpful: GitHub - SkepticMystic/obsidian-openLinkText-mobile-bug

1 Like

Crashes for me as well.

Show debug info output

SYSTEM INFO:
Operating system: android 13 (OnePlus HD1925)
Obsidian version: 1.5.11 (133)
API version: v1.5.11
Login status: logged in
Catalyst license: insider
Live preview: on
Base theme: dark
Community theme: none
Snippets enabled: 2
Restricted mode: off
Plugins installed: 12
Plugins enabled: 12
1: Breadcrumbs v3.6.11
2: Charts v3.9.0
3: Dataview v0.5.66
4: Excalidraw v2.0.26
5: Media DB Plugin v0.6.0
6: Quick Switcher++ v4.0.0
7: QuickAdd v1.8.1
8: Inline Scripts v0.24.12
9: Style Settings v1.0.8
10: Supercharged Links v0.12.1
11: Templater v2.2.3
12: Various Complements v9.4.0

1 Like

Follow-up. I’ve found a workaround. The cause of the issue is an anchor with an href and a click handler. This still works on Desktop and some mobile environments, but the double-navigation crashes Android. Even then, the crash only happens if the double link is outside of a MarkdownEditor (in a View, for example).

The fix was to use a span with only a click handler.

Thanks for the report. Given that this is a problem with the Obsidian API, should this have been posted in developers and api section? I’ll move it there.

1 Like

I’ll take a look at the crashing issue later (not sure what’s causing that) but you’re event listener should probably have an evt.preventDefault() in there to avoid the link behavior from firing

That makes sense. I seem to recall having tried that, but in the -poking-around phase of all this, so perhaps I’m misremembering, or some other issue was interacting weirdly.

I’ve had at least three reports from my plugin’s users of what sounds like the same issue.

  • All are using Android.
  • Links in my toolbars are anchors with hrefs and clickHandlers (code sample below).
  • I’ve also made sure preventDefault is at the top of my clickHandler.
  • Links with this behavior are handled with this.app.workspace.openLinkText

I can try @SkepticMystic 's approach of using spans, but for accessibility (screen readers) I think an anchor should be the way to go?

Here’s how I create items in my plugin’s toolbar:

let toolbarItem = document.createElement("a");
toolbarItem.className = "external-link";
toolbarItem.setAttribute("href", item.link);
toolbarItem.setAttribute("rel", "noopener");
toolbarItem.onclick = (e) => this.toolbarClickHandler(e);

Found this Electron issue (could be completely unrelated/outdated?):