Safari Extension Installing, Not Getting Called

Found the WWDC session about the new stuff in Extensions, looks great, and the session was good.


Generated one, and my toolbar button is showing up but clicking it does nothing. Nothing appears in the console. Then I added some code to make it show a popover and that also does not get called.


The following:


override func toolbarItemClicked(in window: SFSafariWindow) {

// This method will be called when your toolbar item is clicked.

NSLog("The extension's toolbar item was clicked")

window.getToolbarItem { toolbarItem in

toolbarItem?.showPopover()

}

}


The function was already there, I added the iteration over the toolbarItems and the call to showPopover() (per the session).


And then the method, in the handler looks thus:


override func popoverWillShow(in window: SFSafariWindow) {

window.getAllTabs { tabs in

let tabCount = tabs.count

NSLog("found \(tabCount) tabs")

}

}


And this never gets called. Nothing shows up in the console and the breakpoint is never called.

I thought maybe this was because I was using the Xcode beta, so I opened the project in the old Xcode (I am on Catalina), but that did not work either.


Not sure why the session did not release the code?


Anyway this is just a fail for now. If you create a project and don't touch a line of code, it will install the button but it will not do anything.

Hi,


What do you set for Action in you plist?

Popover or command?


Anyway, never got any success with this method with either Popover or Command setting.

😕

Lemme see.. ok I looked and it says Command?

Here is a code example that will explain everything:

class SafariExtensionHandler: SFSafariExtensionHandler {

    override func toolbarItemClicked(in window: SFSafariWindow) {
        // when: info.plist → SFSafariToolbarItem → Action = Command
    }

    override func popoverWillShow(in window: SFSafariWindow) {
        // when: info.plist → SFSafariToolbarItem → Action = Popover
    }

    override func popoverViewController() -> SFSafariExtensionViewController {
        // when: info.plist → SFSafariToolbarItem → Action = Popover
        return SafariExtensionViewController.shared
    }

}
Safari Extension Installing, Not Getting Called
 
 
Q