Display NSPanel from within SFSafariExtensionHandler

On MacOS 10.13 we could display an NSPanel from within SFSafariExtensionHandler as follows:

func showPanel(_ message:String) -> NSPanel {
        let panel:NSPanel = NSPanel()
        panel.level = .floating
        var frame:NSRect = panel.frame
        frame.size = NSSize(width: 400, height:60)
        panel.setFrame(frame, display: true)
        panel.makeKeyAndOrderFront(panel)
        
        let font:NSFont = NSFont.systemFont(ofSize: 20)
        let attributes:[NSAttributedString.Key:Any] = [NSAttributedString.Key.font:font]
        let attributedString:NSAttributedString = NSAttributedString(string: message, attributes:attributes)
        let textField:NSTextField = NSTextField(labelWithAttributedString: attributedString)
        
        panel.contentView = textField
        panel.center()
        
        let application:NSApplication = NSApplication.shared
        application.activate(ignoringOtherApps: true)
        
        return panel
    }


However, on MacOS Mojave 10.14 this no longer works. Instead we receive within the Console the following message:

warning: attempt to begin free window rendezvous for <NSPanel: 0x600002767100> failed due to 
Error Domain=com.apple.ViewBridge Code=10 "(null)" 
UserInfo={com.apple.ViewBridge.error.hint=no host-and-service pairs, 
com.apple.ViewBridge.error.description=NSViewBridgeEntitlementError}


Anyone knows how to display NSPanel (or NSWindow) from within a Safari App Extension?

Replies

Lately bumped into the same problem. It looks like panels can be open in the extension

(a) if it happens to have a toolbar popover;

(b) after the popover has been opened at least once.


It looks like Apple does not initialize some important infrasctructure for windows in the extension process before opening the popover. Not sure whether it's a bug or an intentional limitation.


Incidentally: although our panel (after opening the popover) seems to work normally, it does not seem to be resizable. Pretty darn weird.


Am afraid it did not help much; anyone from Apple who understands this stuff to rescue? We would actually need to be able to open windows and panels from an extension (even without a popover) pretty badly to co-operate with our injected scripts.

Lately, I have found even a plain NSAlert would not work in an extension (unless the popover has been already opened): an attempt to runModal one causes the extension to crash reporting “no service marshals available for modal session”.


We would really need to show transient panels/popovers/pop-up menus (task-specific ones, not just extra items in the generic context menu) from our extension code, to overlay them above the browser window and allow the user thus to control the extension (and through it, the injected JS code).


Is there a way to do that? And if not, is there a chance for it to be added in future versions?


Thanks a big lot!

Can we get some clarification here?


Is there any way to display a NSPanel, NSAlert, NSSavePanel, etc... from within SFSafariExtensionHandler?

I still can't get panels to open from the extension page / safari app. Can we get some clarification?

warning:

unable to obtain service marshal for app-modal session

It would be great if users could accomplish tasks that require open/save panels from the extension without needing to open the containing apps.