Using callback completion with WebView.evaluateJavaScript returns a reference error when run from a widget

I’m evaluating a script in a WebView which takes some time to finish. The completion function doesn’t seem to work inside a widget. It works fine in app. (script file)
Imgur