Kareadita/Kavita · warning · KavitaException

No images found on the specified page

Error message

No images found on the specified page

What it means

Thrown by BookService.CopyImageToTempFromBook (line 1253) when the target XHTML page (matching bookmarkDto.Page and EpubContentType.XHTML_1_1) contains no <img> and no <image> nodes. Used when a user bookmarks/copies an image out of an epub page; the page simply has no embedded images to extract.

Source

Thrown at Kavita.Services/BookService.cs:1253

        var bookPages = await book.GetReadingOrderAsync();
        foreach (var contentFileRef in bookPages)
        {
            if (bookmarkDto.Page != counter || contentFileRef.ContentType != EpubContentType.XHTML_1_1)
            {
                counter++;
                continue;
            }

            var content = await contentFileRef.ReadContentAsync();
            doc.LoadHtml(content);

            var images = doc.DocumentNode.SelectNodes("//img")
                         ?? doc.DocumentNode.SelectNodes("//image");

            if (images == null || images.Count == 0)
            {
                throw new KavitaException("No images found on the specified page");
            }

            if (bookmarkDto.ImageOffset >= images.Count)
            {
                throw new KavitaException($"Image index {bookmarkDto.ImageOffset} is out of range. Page has {images.Count} images");
            }

            var targetImage = images[bookmarkDto.ImageOffset];

            // Get the image source attribute
            var srcAttributeName = GetImageSrcAttributeName(targetImage);

            if (string.IsNullOrEmpty(srcAttributeName))
            {
                throw new KavitaException("Image element does not have a valid source attribute");
            }

            var imageSource = targetImage.Attributes[srcAttributeName].Value;

View on GitHub (pinned to 9c3e540000)

Solutions

  1. On the client, only offer the copy-image action when the page actually rendered <img>/<image> elements.
  2. Server-side, return the image count per page in metadata so the client can disable the action.

Example fix

// before
var images = doc.DocumentNode.SelectNodes("//img") ?? doc.DocumentNode.SelectNodes("//image");
if (images == null || images.Count == 0)
    throw new KavitaException("No images found on the specified page");

// caller — guard before invoking
if (pageImageCount <= 0) return BadRequest("Page has no images");
Defensive patterns

Strategy: validation

Validate before calling

// Only allow copy-image when the page actually has images (client tracks image count)
if (pageImageCount <= 0) { /* disable/hide the copy-image action */ }

Prevention

When it happens

Trigger: Bookmark/copy-image request for a book page that is pure text or whose images are CSS/background only. The bookmarkDto.Page maps to the epub reading-order index.

Common situations: User clicked 'copy image' on a text-only page; the image is a CSS background or SVG referenced differently; ImageOffset computed for a page the client thought had images.

Related errors


AI-assisted analysis of Kareadita/Kavita@9c3e540000 (2026-08-13). Data as JSON: /api/errors/9faeed1dff8fd58b. Report an issue: GitHub.