Subject: bug#77299: eww-auto-rename-buffer 'title interaction with eww-readable-urls

From: Eli Zaretskii <[email-masked]>
Date: Thu, 27 Mar 2025 10:22:08 +0200

> Date: Wed, 26 Mar 2025 11:04:49 -0700
> From: Keith Amidon <[email-masked]>
> 
> I'm trying to use eww with:
> 
> (setq eww-auto-rename-buffer 'title
>        eww-readable-urls '((".*" . t)))
> 
> I'm expecting that this will result in buffer names reflecting
> the titles of the HTML pages. However, what I actually see is
> that all buffers get named "Untitled # EWW", made unique by
> uniquify.
> 
> This seems like a bug to me.
> 
> I believe it arises because the title element of eww-data is set
> to the empty string by eww--before-browse and then set to the
> actual title when shr-insert-document csiteslalls the eww-tag-title
> function via the shr-external-rendering-functions set in
> eww-display-document.
> 
> I think that in the readable case, the content passed to
> shr-insert-document does not include the title element so
> it isn't available from rendering that content.
> 
> It appears to me that eww-readable preserves the title
> in the eww-data plist by resetting it after calling
> eww-before-browse. And in fact, if I set eww-readable-urls to
> nil and go to a site, the buffer is properly named based on
> the title. If I then call eww-readable, it remains named
> based on the title.
> 
> The default readability based-on eww-readable-urls appears
> to happen in eww-display-html, which itself calls
> eww-display-document. The full document hasn't been rendered
> at this point so there is no existing title to preserve.
> 
> I don't think there is a simple fix for this. The fundamental
> problem is that eww only gets the title by rendering the
> original document and in the case of default readable URLs
> it never renders the original document. I thought it might be
> possible to hack eww-score-readability to include the title
> in the readable version but it appears that it is omitting the
> entire head section currently, so it would need fairly
> extensive changes to selectively pass through the title
> without any other head elements.

I agree with your analysis: it's a design problem, which prevents
shr-insert-document from calling eww-tag-title, and thus the title
remains the empty string.  IOW, eww-readable-urls is currently
incompatible with eww-auto-rename-buffer, and moreover, it causes the
URL to be shown as "untitled", even if eww-auto-rename-buffer is not
used.

Hopefully, someone who knows this code and how shr.el works will be
able to come up with a solution.  One possible way is to find the
title before calling shr-insert-document, and then manually setting
the :title property of eww-data when shr-insert-document returns.