95
Merged 3 posts from Safari extensions support.
    3 months later

    I was curious how safari handles extensions so I starting looking around. Not sure if any of this info is helpful:

    From lapcatsoftware.com
    --
    A modern "Safari app extension" has several parts, including the following:

    1. An app, distributed as an .app bundle. The app contains native Mac executable code inside the Contents/MacOS folder of its bundle.

    2. An app extension, distributed as an .appex bundle inside the Contents/PlugIns folder of the .app bundle. The app extension also contains native Mac executable code in the Contents/MacOS folder of its bundle.

    3. JavaScript and CSS, distributed as .js and .css files inside the Contents/Resources folder of the .appex bundle.

    On every launch, Safari runs 2, the native Mac executable code of the .appex bundle, regardless of whether the extension is enabled in Safari's Extensions Preferences. Safari does not load 3, the JavaScript and CSS, unless the extension is enabled.

    --

    It looks like the only extension data that safari store is in ~/Library/Containers/com.apple.Safari/Data/Library/Safari/AppExtensions/Extensions.plist which stores enabled status, allowed domains, etc.

    All extensions are read from the individual host app that wraps the safari extension .appex. Looking at what files safari access It looks like it access the extensions using the Mac binary file in XXX.appex/Contents/MacOS/XXX rather than its resources folder that contains all the js/html.

    Since it's calling Mac binary I'm not sure how safari is loading in its data and it might not be possible to load them into Orion. I haven't seen another browser not made by apple attempt such a thing. There is a Mac binary reader on GitHub that might provide some clues but I have get to look into it.

    There is also a tool in Xcode for converting Web Extension to safari. I haven't look into it much but it might provide some clues on how safari interacts with extensions.

      16 days later

      kenobi If you have some time on your hands, create a prototype app that loads a simple safari extension and we will take it from there.

      4 months later

      I think this is the most important feature request. If at all possible, addding Safari extensions will be a huge benefit to the target market of this app, converting Safari users over to Orion. 👍

        Orionic It is not possible to run Safari extensions (as they are closed source proprietery format).

          2 months later
          2 months later

          Vlad I don't know anything about the Safari extension API but would it be possible to like reverse engineer it?

          • Vlad replied to this.

            Oneechan69 You are welcome to try and let us know if you or someone you know succeeds. Happy to incoprorate it.

              Do you give suggestions like that to everyone?! I've read that a few times here and its ridiculous. Look, not everyone programs, and if they do, they may not be interested or don't have the time to try to program these things themselves.

              I was just asking if you knew or thought it would be possible. Is it?

              • Vlad replied to this.

                Oneechan69 I do not know if it is possible, nobody in the world has done it ever. It would probably take hundreds of hours just to try.

                We do have over 1,500 other issues on this site that we know what to do with, so if anyone figures this out we are happy to incorporate.

                  a year later

                  Also goes well with this issue as a side dish.

                  In order to currently import a Safari web extension, I need to:

                  1. Go into Finder
                  2. Go to my Applications folder
                  3. Find the app associated with the extension
                  4. Choose "Show Package Contents" in the right-click menu
                  5. Go to the "Contents" folder
                  6. Go to the "PlugIns" folder
                  7. Right-click the .appex file
                  8. Choose "Show Package Contents" in the right-click menu
                  9. Go to the "Contents" folder
                  10. Go to the "Resources" folder
                  11. Make sure there's a manifest.json file (validate that this is a web extension and not an app extension)
                  12. Get to Orion's extension manager screen
                  13. Choose "Add Extension"
                  14. Choose "Install from Disk..."
                  15. Drag-and-drop the manifest.json file into the pop-up menu
                  16. Choose "Open"
                  17. Choose "Add"

                  As you can see, it's kind of difficult to do this, and definitely annoying to do with every extension! It's not frustrating, just tedious. I can't just choose to add the .appex file - much less the .app file. I have to add the folder inside the .appex file. I'd really love for this to be automated instead of the manual mess it is right now; that is, you can choose .app and .appex files from the pop-up menu, and if there is a valid web extension to be found (or more than one in some cases), you can import it/them.

                  [This issue #6840 was merged into this main issue #6839, so this introductory paragraph looks weird. I (OP) am editing it to make this clearer.]

                  I've imported a few Safari web extensions following these directions. Particularly, Bitwarden, 1Password for Safari, and Refined GitHub. Bitwarden and Refined GitHub show up as Firefox extensions, while 1Password for Safari shows up as a Chrome extension.

                  1. Download one of these three web extensions from the Mac App Store (or seemingly any other web extension)
                  2. Go into Finder
                  3. Go to the Applications folder
                  4. Find the app associated with the extension
                  5. Choose "Show Package Contents" in the right-click menu
                  6. Go to the "Contents" folder
                  7. Go to the "PlugIns" folder
                  8. Right-click the .appex file
                  9. Choose "Show Package Contents" in the right-click menu
                  10. Go to the "Contents" folder
                  11. Go to the "Resources" folder
                  12. Make sure there's a manifest.json file (validate that this is a web extension and not an app extension)
                  13. Get to Orion's extension manager screen
                  14. Choose "Add Extension"
                  15. Choose "Install from Disk..."
                  16. Drag-and-drop the manifest.json file into the pop-up menu
                  17. Choose "Open"
                  18. Choose "Add"
                  19. Observe that it's labeled as a Firefox/Chrome extension in the manager

                  I expected these extensions to be labeled as a Safari extension.

                  Version 0.99.126.4.1-beta (WebKit 618.1.2)

                  Sonoma (14)

                    Huh, literally no one in in the discord or any of the orion developers ever knew that you could import certain safari extensions. There was never any plan to make this process easier coz nobody knew about it 😄

                    similar to #6839, because nobody ever knew that safari extensions could be imported, orion essentially doesn't know that safari extensions could be installed

                    I'm surprised! Well, there you go - enjoy the knowledge 😅

                    • gp likes this.

                    Of course.
                    This is definitely something very interesting that @Vlad would love to hear about.

                    Also, a few questions:

                    • Do the safari versions seem to work better than the chrome/firefox versions?
                    • Can you install certain safari-only extensions with no chrome/ff counterparts? My understanding was that they could be implemented in swift, which isn't compatible with the js-based extension api.
                    • What about the extensions require money upfront/have a subscription?

                      eirk @Vlad

                      To share the questions already asked in the Discord:

                      • What are Safari web extensions? From Apple: "A Safari web extension adds custom functionality to Safari using JavaScript APIs and common file formats from extensions for Google Chrome, Mozilla Firefox, and Microsoft Edge browsers. While Safari app extensions are useful for sharing code between your native macOS app and Safari, you build Safari web extensions primarily on JavaScript, HTML, and CSS, and can repackage them to work in other browsers."
                      • Does this mean all Safari extensions work? No. Safari app extensions are still proprietary and under lock and key - but funny enough, legacy Safari extensions work the same way as these web extensions do. You can extract the .safariextz file with something like Keka, and then load that folder into Orion.
                      • Doesn't Safari has a severe lack of web extension APIs? Yes. Yes. This does not change that.

                      To answer the questions asked here:

                      • Do the Safari versions seem to work better than the Chrome/Firefox versions? As they're web extensions, they're being interpreted in the same way that a Chrome or Firefox extension would be interpreted by Orion. No difference under the hood. It's up to you and per extension to see whether or not it would work better. (I hear Dark Reader works best in Safari!)
                      • What about the extensions that require money upfront / have a subscription? Not sure what this means. Regardless of if you mean a purchase in the Mac App Store before the app is downloaded, or if you mean a purchase made in the browser after the fact, I don't see why that wouldn't work. If you mean a purchase made in the Mac App Store after the app is downloaded, that's likely dependent on the extension.
                      Merged 2 posts from Safari web extensions are falsely labeled as being from other browsers.