wallabag / android-app

Android application to read your articles saved in your wallabag. You can also easily add new articles.
https://www.wallabag.org
GNU General Public License v3.0
462 stars 260 forks source link

TTS stucks if edit tts_parser.js in some specific ways #1408

Closed void285 closed 1 month ago

void285 commented 1 month ago

Issue details

Duplicate?

no

Actual behaviour

In app/src/main/res/raw/tts_parser.js, there is a function named shouldSkip, when I try editing it to skip pre or code tags, I found if include !== operator or edit the function in some specific ways, a problem occurs: after tap the play button, the play button stays as ... and the TTS wont work.

The original function:

function shouldSkip(element) {
    return element.nodeType === Node.COMMENT_NODE
        || element.tagName === 'SCRIPT' || element.tagName === 'NOSCRIPT'
        // Skip stats icons
        || (element.tagName === 'I' && element.classList.contains('no-tts'));
}

Success conditions:

        || (element.tagName === 'I' && element.classList.contains('no-tts'))
        || (element.tagName === 'PRE' && element.textContent.match(/ /) && element.textContent.match(/[\(\[\{=]/))
        || (element.tagName === 'CODE' && element.textContent.match(/ /) && element.textContent.match(/[\(\[\{=]/))

If include condition like this, the problem occur:

        // cause problem, if change sub condition order
        || (element.classList.contains('no-tts') && element.tagName === 'I')
        // cause problem, if contains !==
        || (element.tagName !== '' && element.classList.contains('no-tts'))
        // cause problem, if no tagName condition, use classList.contains only
        || element.classList.contains('no-tts')
        // cause problem, if use str.includes(' ')
        || (element.tagName === 'PRE' && element.textContent.includes(' ') && element.textContent.match(/[\(\[\{=]/))
        || (element.tagName === 'CODE' && element.textContent.includes(' ') && element.textContent.match(/[\(\[\{=]/))

Environment details

Your experience with wallabag Android app

Wonderfull, wallabag is my most used APP.

void285 commented 1 month ago

I try replace ttsHost.getWebView().evaluateJavascript with ttsHost.getWebView().loadUrl in java/fr/gaulupeau/apps/Poche/tts/WebViewText.java, even worse, the play button always stucks.

di72nn commented 1 month ago

Have you tried using WebView debugging? If I recall correctly, it was quite useful for debugging this functionality. I think all you have to do is to have your device in the same network and open chrome://inspect in Chrome (or Chromium).

void285 commented 1 month ago

Thank you! I debug webview and find the problem is caused by "no contains method on undefined", so I have to check if element.classList is undefined first. Obviously, the script/style elements have no classList properties. And it seems webview dont support str.includes method, if run "abc".includes("a");, it complains undefined is not a function, namely it thinks "abc".includes is undefined.