So after look around some more and trying some new search terms I stumbled on this topic: https://community.atlassian.com/t5/Answers-Developer-Questions/Javascript-code-is-unable-to-load-when-issue-summary-is-open/qaq-p/499651. So I did what suggested there and used:
JIRA.bind(JIRA.Events.ISSUE_REFRESHED, function() {
// your code
});
This did the trick and my code now loads like normal inside the navigator.