1

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.

marko
  • 51
  • 5
  • It sounds like your approach might be viable. Did you try it? What exactly are you asking, because it sounds like you have a plan that you just need to give a shot. Go for it and come back if it doesn't work! – justinw Sep 19 '22 at 19:12
  • @justinw I am asking for an alternative way to the possible approach I proposed. I would like a solution that can access Safari Reader View directly from javascript code running in the browser (e.g., `content.js` or `background.js`). – marko Sep 20 '22 at 06:54
  • Out of curiosity, why do you want an alternative way? Did your approach fail? – justinw Sep 20 '22 at 13:07
  • Safari Extensions have 2 (technically 3) components, web extension that resides in the browser, and app (and app extension) that resides in macOS. I would like to implement whole functionality of my extension in the web extension part so I don't have to move data from one part to another through `nativeMessaging`. Ultimately, it's not that important, but it would be nice to learn how to do it anyways :D – marko Sep 21 '22 at 06:25
  • Got ya. I am not sure you can get past step 2 with Safari Web Extensions API. [toggleReaderMode](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/toggleReaderMode) is not supported in Safari. – justinw Sep 21 '22 at 12:45
  • Did you figure it out? – Vimy Feb 11 '23 at 14:54
  • No, I haven't figured it out. Just went with the Current Solution I outlined above. – marko Feb 15 '23 at 06:28

0 Answers0