Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(clipper): stop logging an error when the popup opens
Elian Dorana04dbb891305
diff --git a/apps/web-clipper/entrypoints/content/index.spec.ts b/apps/web-clipper/entrypoints/content/index.spec.tsindex ad3c79aa7c..f77d7988ae 100644--- a/apps/web-clipper/entrypoints/content/index.spec.ts+++ b/apps/web-clipper/entrypoints/content/index.spec.ts@@ -118,7 +118,7 @@ describe("content script", () => {expect(attributes(container, "a", "href")).toEqual(links);});- it("falls back to the document title and fails without a selection", async () => {+ it("falls back to the document title and answers nothing without a selection", async () => {document.head.innerHTML = "";document.body.innerHTML = "<p id=\"p\">Text</p>";selectRange("p", "p");@@ -133,7 +133,7 @@ describe("content script", () => {window.getSelection()?.removeAllRanges();expect(await send({ name: "trilium-save-selection" })).toBeUndefined();- expect(console.error).toHaveBeenCalledOnce();+ expect(console.error).not.toHaveBeenCalled();});});diff --git a/apps/web-clipper/entrypoints/content/index.ts b/apps/web-clipper/entrypoints/content/index.tsindex 9adf2ada3e..1c85460de7 100644--- a/apps/web-clipper/entrypoints/content/index.ts+++ b/apps/web-clipper/entrypoints/content/index.ts@@ -186,8 +186,10 @@ export default defineContentScript({const container = document.createElement('div');const selection = window.getSelection();+ // The popup asks on every opening, and Firefox reports no range after the page+ // loses focus, so an empty selection is an answer, not an error.if (!selection || selection.rangeCount === 0) {- throw new Error('No selection available to clip');+ return undefined;}for (let i = 0; i < selection.rangeCount; i++) {