7 Replies
      Latest reply on Dec 1, 2018 9:38 AM by OCS1
      esellier Level 1 Level 1 (0 points)



        We are trying to port our legacy webextz extension into a Safari App Extension app.


        First of all, we really lack an actual example (more than what X-Code generates or what was shown at the WDC in 2016).

        A comparison between webextz API and Safari App Extension would be helpful as it is really difficult to guess what is possible and what is not possible anymore (which seems the most common)...



        1/ Is it possible to have a toolbaritem which handles the command messages but still can open a popover?

        We can't find how to open the popover programmatically if toolbarItem Action is set to "Command"

        It would be great to be able, as in a webextz, to set popup per tab


        2/ How to close programmatically the popover (with toolbaritem Action set as Popover)?

        Tried many things, from view controller, but still unsuccessful


        3/ Will extension user settings need to be managed through the Host app?

        Meaning we can't propose settings in the Safari Preferences/Extensions?



        • Re: Safari App Extension - Popover and Command
          tomjohn1028 Level 1 Level 1 (0 points)

          I would also love to be able to open the popover programmatically whent he Action is set to "Command".

          Use case:


          I have a list of supported URLs that my extension injects Scripts, which inject HTML and the Toolbar Item controls some functionality. But on non-whitelisted sites the popover can't do anything.


          I struggled to find an API that could load the popover view from the SafariExtensionHandler.

          • Re: Safari App Extension - Popover and Command
            mtospr Level 1 Level 1 (0 points)

            Have you ever found a solution for 2: Closing popover programmatically? I have the same issue and am too unsuccessful.

            • Re: Safari App Extension - Popover and Command
              bweinstein Apple Staff Apple Staff (20 points)

              1) This is not currently possible.


              Can you explain why you'd like both a Command and Popover? In the case of your extension, would the user know if a click was going to open the popover or dispatch a command?


              2) We are working on an API for this and hope to have it available for extensions soon.


              3) The recommended place for extension settings is in the host app. What kind of settings are you looking to add?

                • Re: Safari App Extension - Popover and Command
                  OCS1 Level 1 Level 1 (0 points)

                  I can't speak for esellier, but we do have a similar case ourselves.


                  Our extension's services depend on its container application (which is essentially a data server for the extension, with some extra GUI). The services provided by the popover are available only if the container is running (and the user is logged into it).


                  We would prefer

                  (a) if the toolbar icon presented the current state of our application;

                  (b) if the container does not run at all, if a click to the toolbar icon launched it;

                  (c) if the container runs, but the user is not logged in, if a click to the toolbar icon opened a login panel in the app;

                  (d) if the container runs and the user is logged in, if a click to the toolbar icon opened the pop-over (whose contents then communicates further with the container through the extension).


                  For the moment and with the current APIs, we more-or-less can do (a), although there's a problem with reflecting the changes when the extension process is not running (compare please the “Keep the extension alive for awhile?” thread: https://forums.developer.apple.com/thread/110979).


                  Nevertheless, we can't achieve (b)-(d). Our current work-around is to have a pop-over containing just the “Launch” or “Login” button for (b)/(c); that's rather ugly and sub-optimal.


                  There are other problems with this approach, too: e.g., if the container application quits or the user logs out while the pop-over is open, we must dynamically switch its contents (to the Launch/Login button) — that leads to pretty ugly extension design. The proper design would be to use two or three different popover view controllers for different cases; but we can't, for we can't close the popover nor switch its current controller if the conditions change whilst the popover is open.


                  Thanks a lot,