7 Replies
      Latest reply on Feb 9, 2020 8:29 PM by Prasana Kannan
      Micro Focus Level 1 Level 1 (0 points)

        Hi, all 

              We are trying to migrate our old safari extension to new app extension. In our our extension, we have the tabs managment mechanism that we can cope with different webpage upon which tab they are inside. But now, we found we have technical problem to do that.    

              The main problem is that we can not get all the opened tabs. Is there any way we can get all the tabs and switch between them?

        • Re: how to do tab management
          OCS1 Level 1 Level 1 (0 points)

          At the moment, this is not possible. Apple is apparently working on such an API (see please https://forums.developer.apple.com/thread/106084#338057 ), but that's the bright future, whilst currently the API is not that bright by far.

           

          For now, I am afraid you are SOL

           

          Far as I know, there are work-arounds to (not reliably, but more-or-less) enumerate all the windows (you can cache them upon a toolbar button validation), and to get a list of all the alive pages (you can inject a script which upon load sends a message, and then cache all pages from which you got that message), but, alas, I never found any work-around to get inactive tabs inside of a window 

          • Re: how to do tab management
            bweinstein Apple Staff Apple Staff (100 points)

            As OCS1 mentioned, this is something we are working on and hope to have in a release for developers soon.

             

            However, would you mind telling me the APIs that you are looking for, and what you hope to achieve by using them?

             

            Thanks!

              • Re: how to do tab management
                OCS1 Level 1 Level 1 (0 points)

                Again, can't speak for Micro Focus; but ourselves, we occasionally need to broadcast some information (originating in our container app) to all our injected scripts in all tabs of all windows: e.g., we need to let our scripts know that the user did log in or log out (compare please https://forums.developer.apple.com/message/341750#341750).

                 

                Anyway, for us, all of these needs can be comparatively easily worked around. Nevertheless, it would be convenient if you could add something more or less like this:

                 

                @interface SFSafariApplication
                +(void)getWindowsWithCompletionHandler:(void(^)(NSArray<sfsafariwindow*>*windows))completionHandler;
                @end
                @interface SFSafariWindow
                @property (readonly) BOOL isActive; // I am not sure if this is feasible synchronously; if not, of course, as a get...handler instead
                -(void)getTabsWithCompletionHandler:(void (^)(NSArray<sfsafaritab*>*tabs))completionHandler;
                @end
                @interface SFSafariTab
                @property (readonly) BOOL isActive; // same as above
                @end

                Thanks a lot,

                OC

                  • Re: how to do tab management
                    bweinstein Apple Staff Apple Staff (100 points)

                    This will be in the next version of Safari. It is current in Safari Technology Preview, but extensions using Safari Technology Preview use Safari's version of the SafariServices framework, so it can't be tested yet.

                     

                    What will be in the next release of Safari:

                    -[SFSafariWindow getAllTabsWithCompletionHandler:]

                    -[SFSafariApplication getAllWindowsWithCompletionHandler:]

                     

                    And then from an SFSafariPage you can get to its containing SFSafariTab, and also go from SFSafariTab -> SFSafariWindow.

                      • Re: how to do tab management
                        Micro Focus Level 1 Level 1 (0 points)

                        Thanks alot, And could we have a a callback to notify the extension that a new tab was opened somehow 

                        • Re: how to do tab management
                          OCS1 Level 1 Level 1 (0 points)

                          From the usability point of view there's no difference of course, but given SFSafariTab responds to the “getPagesWithCompletionHandler:” message (not “getAllPages...”), I believe messages -[SFSafariWindow getTabsWithCompletionHandler:] and -[SFSafariApplication getWindowsWithCompletionHandler:] might be more consistent with the current API, or am I overlooking something of importance here?

                    • Re: how to do tab management
                      Prasana Kannan Level 1 Level 1 (0 points)

                      I had a hard time doing window/tab management, especially hooking a event listener when a window or tab is added, removed or updated.  After some time, I figured out a best possible way to do it with miminal code. Also added identifiers(id) for SFSafariWindow, SFSafariTab and SFSafariPage to uniquely identify each one.

                      Please find out the implementation POC (Implementation in swift)

                      h t t p s : // github.com/prasanaworld/SafariAppExtension-WindowTabManagement