Skip to content
Advertisement

Global not defined when running a JS script in a Java application

I have a js script which I want to execute in my Java application.

I have tried to use the Chromedriver API to do this

But it throws the following exception:

global not defined

I am so confused because the script can simply run with node xx.js

Does this mean the js which uses the global object cannot execute in a Java application?

Advertisement

Answer

According to MDN, global is Node-specific, so you can’t expect to be able to use it if you’re not running under Node. They suggest globalThis as the portable replacement.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement