vomebook commited on
Commit ·
a4c6821
1
Parent(s): 8df7a95
fix(tts): 听书 on another article starts it; keep reading after leaving a standalone Reader
Browse files- static/reader/ui/reader-speech.mjs +46 -0
- static/search/reader-navigation.js +41 -1
- static/tts-client.js +14 -6
- tests/test_reader_speech.py +43 -0
static/reader/ui/reader-speech.mjs
CHANGED
|
@@ -5,6 +5,11 @@
|
|
| 5 |
// DOM text is never modified: highlights use the CSS Custom Highlight API in
|
| 6 |
// the realm (frame document / shadow tree) that owns the range.
|
| 7 |
const SKIP = new Set(["SCRIPT", "STYLE", "NOSCRIPT", "TEMPLATE"]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
const HIGHLIGHT_STYLE = "::highlight(ccrd-speech){background:rgba(138,180,248,.38);color:inherit;text-decoration:underline}";
|
| 9 |
|
| 10 |
function textNodes(root) {
|
|
@@ -398,6 +403,43 @@ export function createReaderSpeech(readerContext) {
|
|
| 398 |
id: documentId(), title: readerSpeechTitle(), adapter: next, host: document.body,
|
| 399 |
tools: document.querySelector(".reader-actions"), buttonClass: "icon-button preview-speech-btn"
|
| 400 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
}
|
| 402 |
|
| 403 |
function rebase(unit) {
|
|
@@ -548,6 +590,10 @@ export function createReaderSpeech(readerContext) {
|
|
| 548 |
function install() {
|
| 549 |
if (installed) return;
|
| 550 |
installed = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
readerContext.readerRuntime.events.on("phase", ({ phase }) => {
|
| 552 |
if (phase === "ready") attach();
|
| 553 |
else if (phase === "disposed") { speech()?.stop?.(); detach(); }
|
|
|
|
| 5 |
// DOM text is never modified: highlights use the CSS Custom Highlight API in
|
| 6 |
// the realm (frame document / shadow tree) that owns the range.
|
| 7 |
const SKIP = new Set(["SCRIPT", "STYLE", "NOSCRIPT", "TEMPLATE"]);
|
| 8 |
+
// A standalone Reader left while reading aloud (← or browser back) records
|
| 9 |
+
// where it was; search/reader-navigation.js resumes it in a background Reader
|
| 10 |
+
// and passes the position through the frame name. Keep both keys in sync.
|
| 11 |
+
const HANDOFF_KEY = "reader-speech-handoff";
|
| 12 |
+
const RESUME_PREFIX = "reader-speech-resume:";
|
| 13 |
const HIGHLIGHT_STYLE = "::highlight(ccrd-speech){background:rgba(138,180,248,.38);color:inherit;text-decoration:underline}";
|
| 14 |
|
| 15 |
function textNodes(root) {
|
|
|
|
| 403 |
id: documentId(), title: readerSpeechTitle(), adapter: next, host: document.body,
|
| 404 |
tools: document.querySelector(".reader-actions"), buttonClass: "icon-button preview-speech-btn"
|
| 405 |
});
|
| 406 |
+
if (resume) { const target = resume; resume = null; resumeAt(target); }
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
// ---- Leaving a standalone Reader while reading aloud -----------------------
|
| 410 |
+
// Unit-local position: adapter offsets depend on the unit the window started at.
|
| 411 |
+
let resume = (() => {
|
| 412 |
+
try {
|
| 413 |
+
if (!String(window.name).startsWith(RESUME_PREFIX)) return null;
|
| 414 |
+
const value = JSON.parse(window.name.slice(RESUME_PREFIX.length));
|
| 415 |
+
window.name = "";
|
| 416 |
+
return Number.isInteger(value?.unit) && Number.isInteger(value?.offset) ? value : null;
|
| 417 |
+
} catch (_) { return null; }
|
| 418 |
+
})();
|
| 419 |
+
|
| 420 |
+
function handoff() {
|
| 421 |
+
try {
|
| 422 |
+
if (readerContext.isReaderOverlayFrame?.()) return; // The search page keeps that one alive.
|
| 423 |
+
const state = speech()?.state?.();
|
| 424 |
+
const owner = state?.adapter;
|
| 425 |
+
// The Reader's disposal may stop the player first; `interrupted` keeps that case.
|
| 426 |
+
if (!(state?.playing || state?.interrupted) || typeof owner?.partAt !== "function" || !Number.isInteger(state.position)) return;
|
| 427 |
+
const part = owner.partAt(state.position);
|
| 428 |
+
if (!part) return;
|
| 429 |
+
sessionStorage.setItem(HANDOFF_KEY, JSON.stringify({ readerUrl: location.href, unit: part.unit,
|
| 430 |
+
offset: Math.max(0, Math.min(part.raw.length, state.position - part.start)), at: Date.now() }));
|
| 431 |
+
} catch (_) { /* Optional: without storage, leaving stops reading as before. */ }
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
async function resumeAt(target) {
|
| 435 |
+
const info = adapter?.source;
|
| 436 |
+
if (!info || target.unit < info.first || target.unit >= info.units) return;
|
| 437 |
+
let owner = adapter;
|
| 438 |
+
if (info.units > 1 && (target.unit < owner.base || !owner.covers(target.unit) && target.unit - owner.base > 2)) owner = rebase(target.unit);
|
| 439 |
+
await owner.ensureUnit(target.unit);
|
| 440 |
+
if (owner !== adapter) return;
|
| 441 |
+
owner.following = true;
|
| 442 |
+
speech()?.readFrom(owner.offsetOf(target));
|
| 443 |
}
|
| 444 |
|
| 445 |
function rebase(unit) {
|
|
|
|
| 590 |
function install() {
|
| 591 |
if (installed) return;
|
| 592 |
installed = true;
|
| 593 |
+
try { if (!readerContext.isReaderOverlayFrame?.()) sessionStorage.removeItem(HANDOFF_KEY); } catch (_) {}
|
| 594 |
+
// ← records it before navigating; pagehide covers browser back and other exits.
|
| 595 |
+
window.addEventListener("pagehide", handoff, { capture: true });
|
| 596 |
+
document.querySelector("#back")?.addEventListener("click", handoff, { capture: true });
|
| 597 |
readerContext.readerRuntime.events.on("phase", ({ phase }) => {
|
| 598 |
if (phase === "ready") attach();
|
| 599 |
else if (phase === "disposed") { speech()?.stop?.(); detach(); }
|
static/search/reader-navigation.js
CHANGED
|
@@ -53,7 +53,9 @@
|
|
| 53 |
return null;
|
| 54 |
}
|
| 55 |
}
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
disposeParked();
|
| 58 |
target.classList.add("reader-overlay-parked");
|
| 59 |
target.setAttribute("inert", "");
|
|
@@ -84,12 +86,18 @@
|
|
| 84 |
});
|
| 85 |
stop.setAttribute("aria-label", "停止朗读并关闭阅读器");
|
| 86 |
bar.append(label, back, play, stop);
|
|
|
|
| 87 |
const sync = () => {
|
| 88 |
const state = speech(target);
|
| 89 |
if (!state?.active) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
if (parked?.frame === target) disposeParked();
|
| 91 |
return;
|
| 92 |
}
|
|
|
|
| 93 |
const title = inFrame(target, "#speech-title")?.textContent?.trim() || "朗读";
|
| 94 |
const status = inFrame(target, "#speech-status")?.textContent?.trim() || "";
|
| 95 |
label.textContent = status ? `${title} · ${status}` : title;
|
|
@@ -277,6 +285,38 @@
|
|
| 277 |
returnFocus = focus;
|
| 278 |
return frame;
|
| 279 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
function accepts(event) {
|
| 281 |
if (!frame || event.origin !== location.origin) return false;
|
| 282 |
if (event.source === frame.contentWindow) return true;
|
|
|
|
| 53 |
return null;
|
| 54 |
}
|
| 55 |
}
|
| 56 |
+
// `restartBy`: a Reader resumed after a page navigation is not reading yet;
|
| 57 |
+
// keep it until then (bounded) instead of disposing it on the first check.
|
| 58 |
+
function park(target, focus, restartBy = 0) {
|
| 59 |
disposeParked();
|
| 60 |
target.classList.add("reader-overlay-parked");
|
| 61 |
target.setAttribute("inert", "");
|
|
|
|
| 86 |
});
|
| 87 |
stop.setAttribute("aria-label", "停止朗读并关闭阅读器");
|
| 88 |
bar.append(label, back, play, stop);
|
| 89 |
+
let started = !restartBy;
|
| 90 |
const sync = () => {
|
| 91 |
const state = speech(target);
|
| 92 |
if (!state?.active) {
|
| 93 |
+
if (!started && Date.now() < restartBy) {
|
| 94 |
+
label.textContent = "正在恢复朗读…";
|
| 95 |
+
return;
|
| 96 |
+
}
|
| 97 |
if (parked?.frame === target) disposeParked();
|
| 98 |
return;
|
| 99 |
}
|
| 100 |
+
started = true;
|
| 101 |
const title = inFrame(target, "#speech-title")?.textContent?.trim() || "朗读";
|
| 102 |
const status = inFrame(target, "#speech-status")?.textContent?.trim() || "";
|
| 103 |
label.textContent = status ? `${title} · ${status}` : title;
|
|
|
|
| 285 |
returnFocus = focus;
|
| 286 |
return frame;
|
| 287 |
}
|
| 288 |
+
// A standalone Reader that was reading aloud when the reader went back here
|
| 289 |
+
// (reader-speech.mjs records it): keep reading in a background Reader.
|
| 290 |
+
// Leaving the page cannot keep its audio; this restarts at that sentence.
|
| 291 |
+
function resumeSpeech() {
|
| 292 |
+
let handoff = null;
|
| 293 |
+
try {
|
| 294 |
+
handoff = JSON.parse(sessionStorage.getItem("reader-speech-handoff") || "null");
|
| 295 |
+
sessionStorage.removeItem("reader-speech-handoff");
|
| 296 |
+
} catch (_) {
|
| 297 |
+
return;
|
| 298 |
+
}
|
| 299 |
+
if (!handoff || !(Date.now() - handoff.at < 30000) || frame || parked || !document.body) return;
|
| 300 |
+
let url;
|
| 301 |
+
try {
|
| 302 |
+
url = parse(handoff.readerUrl);
|
| 303 |
+
} catch (_) {
|
| 304 |
+
return;
|
| 305 |
+
}
|
| 306 |
+
url.searchParams.delete("return");
|
| 307 |
+
url.searchParams.delete("nav");
|
| 308 |
+
const next = document.createElement("iframe");
|
| 309 |
+
next.className = "reader-overlay reader-overlay-parked";
|
| 310 |
+
next.title = "在线阅读";
|
| 311 |
+
next.name = "reader-speech-resume:" + JSON.stringify({ unit: handoff.unit, offset: handoff.offset });
|
| 312 |
+
next.src = url.href;
|
| 313 |
+
document.body.append(next);
|
| 314 |
+
park(next, null, Date.now() + 30000);
|
| 315 |
+
}
|
| 316 |
+
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", resumeSpeech, { once: true });
|
| 317 |
+
else setTimeout(resumeSpeech);
|
| 318 |
+
// A search page restored from the back/forward cache runs no startup code.
|
| 319 |
+
root.addEventListener?.("pageshow", (event) => { if (event.persisted) resumeSpeech(); });
|
| 320 |
function accepts(event) {
|
| 321 |
if (!frame || event.origin !== location.origin) return false;
|
| 322 |
if (event.source === frame.contentWindow) return true;
|
static/tts-client.js
CHANGED
|
@@ -541,7 +541,8 @@ if (typeof document !== "undefined") window.CCRDSpeech = (() => {
|
|
| 541 |
const value = owner;
|
| 542 |
if (value) {
|
| 543 |
for (const job of value.jobs.values()) remember(value, job);
|
| 544 |
-
|
|
|
|
| 545 |
value.cancelled = true; clearTimeout(value.timer);
|
| 546 |
for (const controller of value.controllers) if (!controller.createsJob) controller.abort();
|
| 547 |
for (const job of value.jobs.values()) release(job.id, keepalive);
|
|
@@ -903,21 +904,22 @@ if (typeof document !== "undefined") window.CCRDSpeech = (() => {
|
|
| 903 |
if (job.preloaded) advance(value);
|
| 904 |
pump(value); // First POST directly; no iframe, voices or health round-trips.
|
| 905 |
}
|
| 906 |
-
function fromPreview(offset) {
|
| 907 |
// An adapter loads its text on demand; start() waits for it.
|
| 908 |
if (!preview || (!preview.adapter && !preview.text.trim())) { if (typeof showToast === "function") showToast("请等待预览正文加载完成"); return; }
|
| 909 |
if (offset === undefined && preview.adapter?.locateTop) {
|
| 910 |
// Find (and load up to) the text at the reading position first, so a
|
| 911 |
// paged document is not read from its first loaded unit.
|
| 912 |
const token = ++starting;
|
| 913 |
-
if (!owner) { notice("正在定位当前阅读位置…"); show(); }
|
| 914 |
Promise.resolve(preview.adapter.locateTop()).catch(() => 0).then((found) => {
|
| 915 |
-
if (token === starting && preview?.adapter) fromPreview(plan.safe(preview.text, Number(found) || 0));
|
| 916 |
});
|
| 917 |
return;
|
| 918 |
}
|
| 919 |
if (offset === undefined) offset = visibleOffset();
|
| 920 |
-
|
|
|
|
| 921 |
if (owner && sameSource(owner.snapshot, preview) && seek(owner, offset, true)) return;
|
| 922 |
start(preview.adapter ? preview.snapshot : { id: preview.id, text: preview.text, title: preview.title }, offset);
|
| 923 |
}
|
|
@@ -935,6 +937,11 @@ if (typeof document !== "undefined") window.CCRDSpeech = (() => {
|
|
| 935 |
// window; otherwise "听书" starts where the reader is looking now.
|
| 936 |
if (saved?.snapshot.id === preview?.id && (!preview?.adapter || saved.snapshot.adapter === preview.adapter && !preview.adapter.locateTop)) start(saved.snapshot, saved.position);
|
| 937 |
else fromPreview();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 938 |
} else if (!panel.hidden) hide();
|
| 939 |
else { show(); if (!owner.wantsPlay && owner.snapshot.id === preview?.id) resume(); }
|
| 940 |
}
|
|
@@ -1053,6 +1060,7 @@ if (typeof document !== "undefined") window.CCRDSpeech = (() => {
|
|
| 1053 |
// scrolling the player cannot observe itself (e.g. inside an iframe).
|
| 1054 |
reveal: () => { returnView = null; return locateSource().then(updateLocate); },
|
| 1055 |
viewChanged,
|
| 1056 |
-
state: () => ({ active: !!owner, playing: !!owner?.wantsPlay, adapter: owner?.snapshot.adapter || saved?.snapshot.adapter || null
|
|
|
|
| 1057 |
stop: () => { stop("已停止", true); clearMark(); hide(); } };
|
| 1058 |
})();
|
|
|
|
| 541 |
const value = owner;
|
| 542 |
if (value) {
|
| 543 |
for (const job of value.jobs.values()) remember(value, job);
|
| 544 |
+
// `interrupted`: stopped by leaving the page while playing, not by the listener.
|
| 545 |
+
saved = { snapshot: value.snapshot, position: value.position, history: value.history, pitch: value.pitch, interrupted: keepalive && !!value.wantsPlay };
|
| 546 |
value.cancelled = true; clearTimeout(value.timer);
|
| 547 |
for (const controller of value.controllers) if (!controller.createsJob) controller.abort();
|
| 548 |
for (const job of value.jobs.values()) release(job.id, keepalive);
|
|
|
|
| 904 |
if (job.preloaded) advance(value);
|
| 905 |
pump(value); // First POST directly; no iframe, voices or health round-trips.
|
| 906 |
}
|
| 907 |
+
function fromPreview(offset, chosen = false) {
|
| 908 |
// An adapter loads its text on demand; start() waits for it.
|
| 909 |
if (!preview || (!preview.adapter && !preview.text.trim())) { if (typeof showToast === "function") showToast("请等待预览正文加载完成"); return; }
|
| 910 |
if (offset === undefined && preview.adapter?.locateTop) {
|
| 911 |
// Find (and load up to) the text at the reading position first, so a
|
| 912 |
// paged document is not read from its first loaded unit.
|
| 913 |
const token = ++starting;
|
| 914 |
+
if (!owner || chosen) { notice("正在定位当前阅读位置…"); show(); }
|
| 915 |
Promise.resolve(preview.adapter.locateTop()).catch(() => 0).then((found) => {
|
| 916 |
+
if (token === starting && preview?.adapter) fromPreview(plan.safe(preview.text, Number(found) || 0), chosen);
|
| 917 |
});
|
| 918 |
return;
|
| 919 |
}
|
| 920 |
if (offset === undefined) offset = visibleOffset();
|
| 921 |
+
// 听书 pressed on another article is that choice; other paths still ask.
|
| 922 |
+
if (!chosen && owner && owner.snapshot.id !== preview.id && !confirm("切换到当前预览会停止原朗读,继续吗?")) return;
|
| 923 |
if (owner && sameSource(owner.snapshot, preview) && seek(owner, offset, true)) return;
|
| 924 |
start(preview.adapter ? preview.snapshot : { id: preview.id, text: preview.text, title: preview.title }, offset);
|
| 925 |
}
|
|
|
|
| 937 |
// window; otherwise "听书" starts where the reader is looking now.
|
| 938 |
if (saved?.snapshot.id === preview?.id && (!preview?.adapter || saved.snapshot.adapter === preview.adapter && !preview.adapter.locateTop)) start(saved.snapshot, saved.position);
|
| 939 |
else fromPreview();
|
| 940 |
+
} else if (preview && !sameSource(owner.snapshot, preview)) {
|
| 941 |
+
// 听书 on another article starts that article. It used to toggle the old
|
| 942 |
+
// article's panel, so a press collapsed it and the next one showed it
|
| 943 |
+
// again. The stopped article keeps its position for 继续.
|
| 944 |
+
fromPreview(undefined, true);
|
| 945 |
} else if (!panel.hidden) hide();
|
| 946 |
else { show(); if (!owner.wantsPlay && owner.snapshot.id === preview?.id) resume(); }
|
| 947 |
}
|
|
|
|
| 1060 |
// scrolling the player cannot observe itself (e.g. inside an iframe).
|
| 1061 |
reveal: () => { returnView = null; return locateSource().then(updateLocate); },
|
| 1062 |
viewChanged,
|
| 1063 |
+
state: () => ({ active: !!owner, playing: !!owner?.wantsPlay, adapter: owner?.snapshot.adapter || saved?.snapshot.adapter || null,
|
| 1064 |
+
position: owner ? owner.position : saved ? saved.position : null, interrupted: !owner && !!saved?.interrupted }),
|
| 1065 |
stop: () => { stop("已停止", true); clearMark(); hide(); } };
|
| 1066 |
})();
|
tests/test_reader_speech.py
CHANGED
|
@@ -324,6 +324,49 @@ class ReaderSpeechTest(unittest.TestCase):
|
|
| 324 |
finally:
|
| 325 |
context.close()
|
| 326 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
def test_native_pdf_text_layer_is_read_and_image_is_not_offered(self):
|
| 328 |
context, page, posts, errors = self.open("pdf", minimal_pdf(), "application/pdf")
|
| 329 |
try:
|
|
|
|
| 324 |
finally:
|
| 325 |
context.close()
|
| 326 |
|
| 327 |
+
def test_leaving_a_standalone_reader_keeps_reading_on_the_search_page(self):
|
| 328 |
+
# A Reader opened directly (not as an overlay) cannot keep its audio when
|
| 329 |
+
# ← navigates to the search page; that page resumes it at the same sentence.
|
| 330 |
+
context, page, posts, errors = self.open("txt", TEXT.encode(), "text/plain; charset=utf-8")
|
| 331 |
+
try:
|
| 332 |
+
self.play(page, posts)
|
| 333 |
+
for _ in range(3):
|
| 334 |
+
clip = page.locator("#speech-audio").evaluate("n => n.src")
|
| 335 |
+
page.locator("#speech-next").click()
|
| 336 |
+
wait(page, f"() => document.querySelector('#speech-audio').src !== {json.dumps(clip)}")
|
| 337 |
+
# The sentence being read (the resumed job starts at its beginning).
|
| 338 |
+
playing = page.evaluate("""() => { const s = CCRDSpeech.state(), t = s.adapter.text; let i = s.position;
|
| 339 |
+
while (i > 0 && !/[。!?\\n]/.test(t[i - 1])) i--; return t.slice(i, i + 8).trim(); }""")
|
| 340 |
+
self.assertTrue(playing and not playing.startswith("第0段"), playing)
|
| 341 |
+
before = len(posts)
|
| 342 |
+
reader = page.url
|
| 343 |
+
base = reader.split("reader.html")[0]
|
| 344 |
+
page.goto(base + "search/reader-navigation.js", wait_until="domcontentloaded") # leaving fires pagehide
|
| 345 |
+
page.add_style_tag(content=(ROOT / "static/style.css").read_text(encoding="utf-8"))
|
| 346 |
+
page.add_script_tag(content=(ROOT / "static/search/reader-navigation.js").read_text(encoding="utf-8"))
|
| 347 |
+
page.evaluate("url => { window.__nav = VoiceOfMLReaderNavigation.createNavigation(new URL(url).pathname, { resume: next => __nav.mount(new URL(next)) }); }", reader)
|
| 348 |
+
bar = page.locator(".reader-speech-mini")
|
| 349 |
+
bar.wait_for(timeout=5000)
|
| 350 |
+
kept = page.wait_for_selector("iframe.reader-overlay-parked", state="attached")
|
| 351 |
+
self.assertEqual(page.evaluate("() => getComputedStyle(document.querySelector('iframe.reader-overlay-parked')).visibility"), "hidden")
|
| 352 |
+
frame = kept.content_frame()
|
| 353 |
+
wait(frame, "()=>{const a=document.querySelector('#speech-audio');return !!a&&!a.paused&&a.currentTime>0.05}", 30000)
|
| 354 |
+
self.assertTrue(posts[before]["text"].lstrip().startswith(playing), (playing, posts[before]["text"][:30]))
|
| 355 |
+
self.assertEqual(frame.evaluate("() => window.name"), "")
|
| 356 |
+
self.assertEqual(page.evaluate("() => sessionStorage.getItem('reader-speech-handoff')"), None)
|
| 357 |
+
bar.get_by_role("button", name="返回阅读").click()
|
| 358 |
+
self.assertEqual(page.locator(".reader-speech-mini").count(), 0)
|
| 359 |
+
self.assertFalse(frame.evaluate("() => document.querySelector('#speech-audio').paused"))
|
| 360 |
+
# A Reader left without reading aloud (or reloaded) leaves nothing to resume.
|
| 361 |
+
frame.locator("#speech-stop").click()
|
| 362 |
+
page.goto(reader, wait_until="domcontentloaded")
|
| 363 |
+
wait(page, "() => document.documentElement.dataset.readerPhase === 'ready'", 30000)
|
| 364 |
+
page.goto(base + "search/reader-navigation.js", wait_until="domcontentloaded")
|
| 365 |
+
self.assertEqual(page.evaluate("() => sessionStorage.getItem('reader-speech-handoff')"), None)
|
| 366 |
+
self.assertFalse(errors, errors)
|
| 367 |
+
finally:
|
| 368 |
+
context.close()
|
| 369 |
+
|
| 370 |
def test_native_pdf_text_layer_is_read_and_image_is_not_offered(self):
|
| 371 |
context, page, posts, errors = self.open("pdf", minimal_pdf(), "application/pdf")
|
| 372 |
try:
|