Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Firefox reader view operate

Summary

I am looking for the criteria by which I can create a webpage and be [fairly] sure it will appear in the Firefox Reader View, if user desired.

Some sites have this option, some do not. Some with more text do not have this option than others with much less text. Stack Overflow for instance displays only the question rather than any answers in Reader View.

Question

I have had my Firefox upgraded from 38.0.1 to 38.0.5 and have found a new feature called ReaderView - which is a sort of overlay which removes "page clutter" and makes text easier to read. Readerview is found in the right hand side of the address bar as a clickable icon on certain pages.

This is fine, but from the programming point of view I want to know how "reader view" works, which criteria of which pages it applies to. I have done some exploration of the Mozilla Firefox website with no clear answers (sod all programming answers of any sort I found), I have of course Googled / Binged this and this only came back with references to Firefox addons - this is not an addon but a staple part of the new Firefox version.

I made an assumption that readerview used HTML5 and would extract <article> contents but this is not the case as it works on Wikipedia which does not appear to use <article> or similar HTML5 tags, instead the readview extracts certain <div>s and displays them alone. This feature works on some HTML5 pages - such as wikipedia - but then not others.

If anyone has any ideas how Firefox ReaderView actually operates and how this operation can be used by website developers, can you share? Or if you can find where this information can be located, can you point me in the right direction - as I have not been able to find this.

like image 464
Martin Avatar asked Jun 05 '15 08:06

Martin


People also ask

What is reader view in Firefox?

Reader view on Firefox for Android may sometimes strips away images, ads, videos and menus from a web page, so you can focus on reading. Through the reader view, You can change the font type, increase or decrease the font size and change the background color.

How does reader mode work?

The Reader mode, built into Apple's Safari browser since 2010 and available on macOS and iOS, strips away web advertisements and the page's navigational design to present an article's text and basic images in a clean and uncluttered format.

How do I customize the reader view in Firefox?

You can change them by going to Preferences > Content > Advanced and choosing your fonts for serif and sans-serif styles. As you can see in the images above, I have changed the serif font to Seravek. At least in Firefox 47 those settings do not affect Reader View in any way.

What is a browser reader view?

To reduce the clutter on the pages that distracts from what we want to read, most browsers have an option called “Reader Mode” or “Reader View.” When enabled, this view takes away all of the excess information and shows you only the article and its images.


2 Answers

Reading through the gitHub code, this morning, the process is that page elements are listed in a likelyhood order - with <section>,<p>,<div>,<article> at the top of the list (ie most likely).

Then each of these "nodes" is given a score based on things such as comma counts and class names that apply to the node. This is a somewhat multi-faceted process where scores are added for text chunks but also scores are seemingly reduced for invalid parts or syntax. Scores in sub-parts of "node" are reflected in the score of the node as a whole. ie the parent element contains the scores of all lower elements, I think.

This score value decides if the HTML page can be "page viewed" in Firefox.

I am not absolutely clear if the score value is set by Firefox or by the readability function.

Javascript is really not my strong point,and I think someone else should check over the link provided by Richard ( https://github.com/mozilla/readability ) and see if they can provide a more thorough answer.

What I did not see but expected to see was score based on amount of text content in a <p> or a <div> (or other) relevant tags.

Any improvements on this question or answer, please share!!

EDIT: Images in <div> or <figure> tags (HTML5) within the <p> element appear to be retained in the Reader View when the page text content is valid.

like image 24
Martin Avatar answered Oct 09 '22 19:10

Martin


You need at least one <p> tag around the text, that you want to see in Reader View, and at least 516 characters in 7 words inside the text.

for example this will trigger the ReaderView:

<body> <p>  123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789  123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789  123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789  123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789  123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789  123456789 123456 </p> </body> 

See my example at https://stackoverflow.com/a/30750212/1069083

like image 106
rubo77 Avatar answered Oct 09 '22 20:10

rubo77