gildas-lormeau/SingleFile · warning · Error

No selected content found

Error message

No selected content found

What it means

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.

Source

Thrown at src/core/content/content.js:220

	const pingInterval = setInterval(() => {
		browser.runtime.sendMessage({ method: "ping" }).then(() => { });
	}, 15000);
	const options = message.options;
	let selectionFound;
	if (options.selected || options.optionallySelected) {
		selectionFound = await ui.markSelection(options.optionallySelected);
	}
	if (processing || bootstrap && bootstrap.pageInfo.processing) {
		clearInterval(pingInterval);
		throw new Error("SingleFile is already processing this page");
	}
	options.visitDate = bootstrap ? bootstrap.pageInfo.visitDate : new Date();
	if (options.optionallySelected && selectionFound) {
		options.selected = true;
	}
	if (options.selected && !selectionFound) {
		clearInterval(pingInterval);
		throw new Error("No selected content found");
	}
	if (bootstrap) {
		bootstrap.pageInfo.processing = true;
	}
	processing = true;
	try {
		return await processPage(options);
	} finally {
		processing = false;
		if (bootstrap) {
			bootstrap.pageInfo.processing = false;
		}
		clearInterval(pingInterval);
	}
}

async function processPage(options) {
	const frames = singlefile.processors.frameTree;

View on GitHub (pinned to 517fb7c5cf)

Solutions

  1. Have the user make a selection before triggering a selected capture.
  2. Omit selected (or set it false) to capture the full page instead.
  3. If using optionallySelected, handle the no-selection case by falling back to a full-page capture.
  4. Re-trigger the selection UI (markSelection) before capture in automated flows.

Example fix

// before
await sendMessage({ method: 'capture', selected: true }); // throws if nothing selected
// after
const hasSelection = await checkSelection();
await sendMessage({ method: 'capture', selected: hasSelection });
Defensive patterns

Strategy: validation

Validate before calling

// before requesting a selected capture, ensure a selection exists
const hasSelection = window.getSelection && !window.getSelection().isCollapsed;

Type guard

function hasUserSelection() {
  const sel = window.getSelection();
  return !!sel && sel.rangeCount > 0 && !sel.isCollapsed && sel.toString().trim().length > 0;
}

Try / catch

try {
  await capture({ selected: true });
} catch (e) {
  if (e.message === 'No selected content found') {
    await capture({ selected: false }); // fall back to full page
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gildas-lormeau/SingleFile@517fb7c5cf (2026-09-01). Data as JSON: /api/errors/147d9767c05094a7. Report an issue: GitHub.