Background
I am developing a Safari Web Extension and need to do following (simplified):
- Initiate action from extension popup.
- Extract main text from the opened web page.
- Process the text in the cloud.
- 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:
- Initiate action from Extension popup.
- Send a message to Extension's macOS app.
- In macOS app initiate
SFSafariViewController
withentersReaderIfAvailable: true
in itsConfiguration
. - In macOS extract text from that Reader View. (not sure if this is possible, but I assume it is).
- Two alternatives here (not really important for the question):
- Send back that text to Web Extension and continue cloud processing from there (as done before).
- 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.