Skip to content

"Cannot read properties of null (reading 'src')" exception thrown when using alphaTab in Javascript module #666

@yshlin

Description

@yshlin

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

I'm trying to develop a toast UI editor plugin that uses alphaTex to visualize guitar tabs.
And I found that when I use alphaTab in a Javascript module,
I get an exception: "Cannot read properties of null (reading 'src')" when initializing alphaTab,
and then the initialization process is interrupted.

Expected Behavior

Because there's no "document.currentScript" in javascript module environment,
it would be safer to have null check on document.currentScript before returning document.currentScript.src.
So the initialization process won't be blocked due to the problem.

Steps To Reproduce

  1. create a javascript module
  2. import alphaTab
  3. run the script
  4. see the exception in console log

Link to jsFiddle, CodePen, Project

https://jsfiddle.net/yshlin/fo0pL65u/10/

Found in Version

1.2

Platform

Web

Environment

- **OS**: macOS 11.6
- **Browser**: Chrome 94.0.4606.61

Anything else?

Still seeing the problem on the develop branch:
https://github.com/CoderLine/alphaTab/blob/develop/src/Environment.ts#L235

I was able to get my code to work after fixing this line.

Metadata

Metadata

Assignees

Labels

platform-javascriptRelated to the JavaScript version of alphaTabstate-acceptedThis is a valid topic to work on.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions