Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Safari Extension Companion is always null

I am developing a Safari Extension for my local Mac App, I want to use SafariExtension Companion to communicate between them.

However, in my Global.html of the extension, whenever I am trying to get safari.extension.companion, it is always null. Do I setup the extension wrong?

Besides, according to the guide, I can use safari.extension.addEventListener to listen the message from local app, however, when I debug the extension, it prompts me safari.extension.addEventListener is undefined, why is that?

Answer: safari.application.addEventListener is correct, Apple write a wrong document.

I do setup the exact Companion Bundle Identifier in Extension Builder as the identifier which I set in Xcode for the safari companion according to the guide. Is there anything else I miss? Please help!!!

like image 484
Terence Avatar asked Dec 08 '15 17:12

Terence


People also ask

Why are my Extensions not working in Safari?

Check Safari extensions If you installed any Safari extensions, make sure that they are up to date. You can also try turning extensions off. From the menu bar in Safari, choose Safari > Settings (or Preferences). Click Extensions, then deselect the checkbox for each extension to turn it off.

How do I give permission to Safari Extensions?

In iOS, the user can open the Settings app, then choose Safari > Extensions in the General group. Then they can tap an extension to see which websites have been configured for the extension, and can change the permission status for a selected website to Ask, Allow, or Deny.

What does manage Extensions mean in Safari?

In the Safari app , you can install extensions to customize the way your browser works. For example, extensions can help you find coupons when shopping, block content on websites, and more.


1 Answers

A Safari extension companion is a type of a MacOS X app extension. Those are shipped as part of application bundles. When the app is installed (the bundle is copied to Applications), Safari picks up the extension.

First, you need an Xcode project with a target of type "Cocoa application" ("Command line tool" won't do). Then you need to create a target of type "Safari Extension Companion", and you have a chance to specify the primary app while creating it.

When you build and archive the app, and export the archive, you get an option to add the extension to the app bundle. Then install the app bundle.

Make sure the bundle ID of the extension matches the setting in the Safari Extension Builder. Also, make sure the app and the Safari extension are both signed, and the keys have matching developer IDs. For certificate type on MacOS X, choose "Developer ID" - first when requesting, then when exporting the bundle from the build archive.

EDIT: when the native companion crashes, Safari quietly disables it. If you remove and reinstall the app bundle, and also restart Safari, it loves the companion again.

like image 74
Seva Alekseyev Avatar answered Sep 29 '22 12:09

Seva Alekseyev