{"record":{"id":"147d9767c05094a7","repo":"gildas-lormeau/SingleFile","slug":"no-selected-content-found","errorCode":null,"errorMessage":"No selected content found","messagePattern":"No selected content found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/core/content/content.js","lineNumber":220,"sourceCode":"\tconst pingInterval = setInterval(() => {\n\t\tbrowser.runtime.sendMessage({ method: \"ping\" }).then(() => { });\n\t}, 15000);\n\tconst options = message.options;\n\tlet selectionFound;\n\tif (options.selected || options.optionallySelected) {\n\t\tselectionFound = await ui.markSelection(options.optionallySelected);\n\t}\n\tif (processing || bootstrap && bootstrap.pageInfo.processing) {\n\t\tclearInterval(pingInterval);\n\t\tthrow new Error(\"SingleFile is already processing this page\");\n\t}\n\toptions.visitDate = bootstrap ? bootstrap.pageInfo.visitDate : new Date();\n\tif (options.optionallySelected && selectionFound) {\n\t\toptions.selected = true;\n\t}\n\tif (options.selected && !selectionFound) {\n\t\tclearInterval(pingInterval);\n\t\tthrow new Error(\"No selected content found\");\n\t}\n\tif (bootstrap) {\n\t\tbootstrap.pageInfo.processing = true;\n\t}\n\tprocessing = true;\n\ttry {\n\t\treturn await processPage(options);\n\t} finally {\n\t\tprocessing = false;\n\t\tif (bootstrap) {\n\t\t\tbootstrap.pageInfo.processing = false;\n\t\t}\n\t\tclearInterval(pingInterval);\n\t}\n}\n\nasync function processPage(options) {\n\tconst frames = singlefile.processors.frameTree;","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/gildas-lormeau/SingleFile/blob/517fb7c5cf2096d89933b747e862d8ecf616a9f9/src/core/content/content.js#L202-L238","documentation":"When capture options request selected content (options.selected) the content script first asks the UI to mark the user's selection (ui.markSelection). If no selection exists on the page, capturePage throws 'No selected content found' rather than capturing the whole page.","triggerScenarios":"Calling capture with selected=true (or optionallySelected=true with selectionFound=false afterwards) on a page where the user has not selected any content via SingleFile's selection mode.","commonSituations":"Automated/external capture requests that always pass selected:true without user interaction; the user pressed 'capture selection' before selecting anything; selection markup was cleared by a page re-render before capture started.","solutions":["Have the user make a selection before triggering a selected capture.","Omit selected (or set it false) to capture the full page instead.","If using optionallySelected, handle the no-selection case by falling back to a full-page capture.","Re-trigger the selection UI (markSelection) before capture in automated flows."],"exampleFix":"// before\nawait sendMessage({ method: 'capture', selected: true }); // throws if nothing selected\n// after\nconst hasSelection = await checkSelection();\nawait sendMessage({ method: 'capture', selected: hasSelection });","handlingStrategy":"validation","validationCode":"// before requesting a selected capture, ensure a selection exists\nconst hasSelection = window.getSelection && !window.getSelection().isCollapsed;","typeGuard":"function hasUserSelection() {\n  const sel = window.getSelection();\n  return !!sel && sel.rangeCount > 0 && !sel.isCollapsed && sel.toString().trim().length > 0;\n}","tryCatchPattern":"try {\n  await capture({ selected: true });\n} catch (e) {\n  if (e.message === 'No selected content found') {\n    await capture({ selected: false }); // fall back to full page\n  }\n}","preventionTips":["Only pass selected:true when the user actually made a selection","Use optionallySelected plus a full-page fallback","Remind users to select content before 'capture selection'"],"tags":["user-input","selection","content-script"],"backgroundTag":"no-selection-found","analyzedSha":"517fb7c5cf2096d89933b747e862d8ecf616a9f9","analyzedAt":"2026-09-01T10:05:25.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}