SpannableString newCount;
card.jsfunction newCardCount(value) {
window.newVar = value;
console.log("value from card.js : " + value);
}
@Override
public void onPageFinished(WebView view, String url) {
Timber.d("onPageFinished triggered");
drawFlag();
drawMark();
view.loadUrl("javascript:onPageFinished();");
view.loadUrl("javascript:newCardCount(\"" + newCount.toString() + "\")");
}
<script>
console.log("value from __viewer__.html : "+window.newVar);
</script>
It giving undefined.
It should give the value of newCount.
It is giving undefined.

2020-05-18 11:34:28.217 28315-28315/com.ichi2.anki D/AbstractFlashcardViewer: fillFlashcard()
2020-05-18 11:34:28.217 28315-28315/com.ichi2.anki D/AbstractFlashcardViewer: base url = file:///storage/emulated/0/AnkiDroid/collection.media/
2020-05-18 11:34:28.222 28315-28315/com.ichi2.anki I/AbstractFlashcardViewer: AbstractFlashcardViewer:: Question successfully shown for card id 1584530770902
2020-05-18 11:34:28.226 28315-28315/com.ichi2.anki D/Collection: undoAvailable() undo size: 7
2020-05-18 11:34:28.243 28315-28315/com.ichi2.anki D/CollectionTask: enabling garbage collection of mPreviousTask...
2020-05-18 11:34:28.248 28315-28315/com.ichi2.anki D/Collection: undoAvailable() undo size: 7
2020-05-18 11:34:28.320 28315-28315/com.ichi2.anki I/chromium: [INFO:CONSOLE(268)] "value from __viewer__.html : undefined", source: file:///storage/emulated/0/AnkiDroid/collection.media/__viewer__.html (268)
2020-05-18 11:34:28.330 28315-28315/com.ichi2.anki D/AbstractFlashcardViewer$CardViewerWebClient: onPageFinished triggered
2020-05-18 11:34:28.333 28315-28315/com.ichi2.anki D/AbstractFlashcardViewer$CardViewerWebClient: onPageFinished triggered
2020-05-18 11:34:28.349 28315-28315/com.ichi2.anki I/chromium: [INFO:CONSOLE(99)] "value from card.js : 14", source: file:///android_asset/scripts/card.js (99)
2020-05-18 11:34:28.353 28315-28315/com.ichi2.anki I/chromium: [INFO:CONSOLE(99)] "value from card.js : 14", source: file:///android_asset/scripts/card.js (99)
Enter an [x] character to confirm the points below:
so you know the method is executing (you have the console.log from debugging) but window.newVar is undefined. You should check if window.newVar has a value even after you set it, right in that function. Perhaps there is some oddity with referring to the variable? I don't have a lot of experience with the javascript environment inside Chrome unfortunately so I'm not sure sorry
Shot in the dark: HTML errors causing JS execution inside __viewer__.html to fail. (#5273)
The function newCardCount(value) called before onPageFinished. So, might be it should called from other function.
Thank you @mikehardy @david-allison-1
I figured out it.
Using this I get the value
<script>
setTimeout(function(){
console.log("value from __viewer__.html : "+window.newVar);
}, 1000);
</script>

Most helpful comment
Thank you @mikehardy @david-allison-1
I figured out it.
Using this I get the value