How to access Safari browser Reader Mode content from my Safari Extension?

623 Views Asked by At

Background

I am developing a Safari Web Extension and need to do following (simplified):

  1. Initiate action from extension popup.
  2. Extract main text from the opened web page.
  3. Process the text in the cloud.
  4. Update DOM with processed text.

Current Situation

The Extension uses https://github.com/mozilla/readability, directly from its content.js, to extract the main text from the page and that works fine in most cases, and I can proceed with steps 2 and 3.

However, I noticed that Safari Reader View produces good results, arguably better than Readability. So I want to try and replace Readability with Safari Reader View for this text extraction.

Problem

How can I access Safari Reader View content/text directly from content.js of my Extension?

One possible approach (that I haven't tested) would be something like this:

  1. Initiate action from Extension popup.
  2. Send a message to Extension's macOS app.
  3. In macOS app initiate SFSafariViewController with entersReaderIfAvailable: true in its Configuration.
  4. In macOS extract text from that Reader View. (not sure if this is possible, but I assume it is).
  5. Two alternatives here (not really important for the question):
    1. Send back that text to Web Extension and continue cloud processing from there (as done before).
    2. Initiate cloud processing from macOS app and send only result to the Web Extension.

Ultimately, I might try that, but first I would like to avoid involving macOS app part of this Extension.

0

There are 0 best solutions below