diff --git a/test/integration/test_utils.mjs b/test/integration/test_utils.mjs index e8b4ef5c1..c49cb1daa 100644 --- a/test/integration/test_utils.mjs +++ b/test/integration/test_utils.mjs @@ -135,6 +135,7 @@ function getSelector(id) { async function getRect(page, selector) { // In Chrome something is wrong when serializing a `DomRect`, // so we extract the values and return them ourselves. + await page.waitForSelector(selector); return page.$eval(selector, el => { const { x, y, width, height } = el.getBoundingClientRect(); return { x, y, width, height }; diff --git a/web/pdf_viewer.js b/web/pdf_viewer.js index 23664ab9e..256ad0e3a 100644 --- a/web/pdf_viewer.js +++ b/web/pdf_viewer.js @@ -1122,9 +1122,7 @@ class PDFViewer { this.#hiddenCopyElement?.remove(); this.#hiddenCopyElement = null; - this.#onPageRenderedCallback = null; - clearTimeout(this.#switchAnnotationEditorModeTimeoutId); - this.#switchAnnotationEditorModeTimeoutId = null; + this.#cleanupSwitchAnnotationEditorMode(); } #ensurePageViewVisible() { @@ -2263,6 +2261,17 @@ class PDFViewer { ]); } + #cleanupSwitchAnnotationEditorMode() { + if (this.#onPageRenderedCallback) { + this.eventBus._off("pagerendered", this.#onPageRenderedCallback); + this.#onPageRenderedCallback = null; + } + if (this.#switchAnnotationEditorModeTimeoutId !== null) { + clearTimeout(this.#switchAnnotationEditorModeTimeoutId); + this.#switchAnnotationEditorModeTimeoutId = null; + } + } + get annotationEditorMode() { return this.#annotationEditorUIManager ? this.#annotationEditorMode @@ -2296,14 +2305,7 @@ class PDFViewer { const { eventBus } = this; const updater = () => { - if (this.#onPageRenderedCallback) { - eventBus._off("pagerendered", this.#onPageRenderedCallback); - this.#onPageRenderedCallback = null; - } - if (this.#switchAnnotationEditorModeTimeoutId !== null) { - clearTimeout(this.#switchAnnotationEditorModeTimeoutId); - this.#switchAnnotationEditorModeTimeoutId = null; - } + this.#cleanupSwitchAnnotationEditorMode(); this.#annotationEditorMode = mode; eventBus.dispatch("annotationeditormodechanged", { source: this, @@ -2329,15 +2331,14 @@ class PDFViewer { if (isEditing && editId && idsToRefresh) { // We're editing an existing annotation so we must switch to editing // mode when the rendering is done. - const { signal } = this.#eventAbortController; + this.#cleanupSwitchAnnotationEditorMode(); this.#onPageRenderedCallback = ({ pageNumber }) => { idsToRefresh.delete(pageNumber); if (idsToRefresh.size === 0) { - eventBus._off("pagerendered", this.#onPageRenderedCallback); - this.#onPageRenderedCallback = null; this.#switchAnnotationEditorModeTimeoutId = setTimeout(updater, 0); } }; + const { signal } = this.#eventAbortController; eventBus._on("pagerendered", this.#onPageRenderedCallback, { signal }); return; }