🐛 Fix random translation failures and stuck target language (closes #2) #8
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "jiaofangkai926/deepl-scraper:fix/issue-2-reliable-translation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Issue #2 reports random translation errors, e.g.
when running something like
translate("Mittel", "de-de", "ja-JA").Root cause
The translation flow is a sequence of UI automation steps, but each step assumed the UI was already in the expected state:
page.typeis called →No node found for selector: .lmt__source_textarea, i.e. the failure reported in the issue.(The
f684f108commit already added awaitForSelectorfor the source textarea; this PR covers the remaining cases.)Solution
chooseLanguage()now waits for the option's own panel and verifies the panel's label afterwards; if the expected language did not get selected, it re-opens the menu and retries (up to 3 attempts), failing withLANGUAGE_SWITCH_FAILED:source/LANGUAGE_SWITCH_FAILED:targetif the switch really could not happen.waitForSelector(..., { visible: true })before typing.requestfinishedlistener is registered before typing, so a request fired right after the last keystroke cannot be missed.translate()retries once on a fresh page when the failure looks transient (missing node / navigation or wait timeout); non-transient errors (e.g.TRANSLATION_RESULT_UNAVAILABLE, invalid language arguments) fail immediately instead of retrying forever.1.0.12, changelog updated.Verification
node --check index.jspasses.I verified the repaired behavior deterministically with a local fixture server (fake DeepL page + translation JSON endpoint, driven by the real
translate()viaDEEPL_TRANSLATOR_HOMEPAGE, Chrome viaPUPPETEER_EXECUTABLE_PATH). The fixture injects exactly the failure modes from this issue:target.lang === 'ja'GET /translator×2)resultTRANSLATION_RESULT_UNAVAILABLE, no retryde-de/JA-jaINVALID_*_LANGUAGE, unchanged behaviorNote: DeepL's live site has since been redesigned (the old markup/selectors this module targets is from the 2019–2020 era), so live end-to-end verification against
deepl.comis not possible with the original selectors; the fixture-based approach exercises the repaired logic itself.Impact scope
index.jsflow control changed; public API, return shape and error contracts are unchanged, two errors added and documented.Closes #2.
Hi,
Thank you for taking the time to submit a PR.
Actually, I've abandoned the development of
deepl-scraperand several other scraping projects a while ago as I lost interest in playing the cat & mouse game with corporate developers.Moreover, in the AI era, having a small model running locally (e.g. using MNN) will use less compute than running a headless Chrome browser.
I'm going to close this and archive this repository.
Sorry and good luck
PS: feel free to join my Discord community if you wish to continue this conversation though, cause I know the archiving action will make this read-only and I don't mean to prevent you from responding.