Safari App Extension > Apple's tutorial does not work correctly

I'm having a first look at Safari App Extensions (1) and so followed Apple's tutorial at this URL:


https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/SafariAppExtension_PG/CreatingandTestingYourFirstSafariAppExtension.html#//apple_ref/doc/uid/TP40017319-CH11-SW1


While clicking on the - button does produce a log entry, the dispatched message sent by the script.js injected script never appears (2) when loading or reloading a page.


I'm currently running this thing as an unsigned application/extension (as is the case in the tutorial).


Question:


Which instructions am I missing to make this simple example work?



1. Based on what I'm reading on this forum and because of the OS minimum requirements, I will probably look into a Safari Extension anyway.


2. Logging is working fine on this macOS 10.3.2 system, the "Month 13 is out of bounds" message is repeated dozens of time …

Replies

A few questions:


1) If you open Web Inspector, do you see your extension's content script being injected into the page?

2) What websites does your extension have permission to access?

3) If you put a console.log in your extension's content script, do you see that in Web Inspector?

1) Yes, it's listed in the Extension Scripts folder/group.


2) SFSafariWebsiteAccess has been set to 'All'.


BTW, it's a bit shortsighted that the Safari Extension target template sets this by default to 'Some' + *webkit.org.


3) Not sure of what you mean by the content script. If you mean the script.js file, adding a console.log("Month 14 is also out of bounds"); line before the document.addEventListener(…) one works (the log appears in the Web Inspector).

What happens if you attach to your Safari App Extension's process in Xcode and try and set a breakpoint on the message handler? Is it ever hit?


Where are you looking for the logging from the native code in your extension?

- Never hit.


- Xcode output "console", Console.app system.log and Safari JavaScript Console.

Can you please file a radar and attach the project you are using? I was able to just write a sample app that did message dispatch between the content script and the Safari App Extension without any issues.


Thanks!

Brian

Hey! Were you able to figure this out? I'm having the exact same issue

What version of MacOS, Xcode, and Safari are you using? I see the same behavior as the OP. I'm using Macos 10.3.4, Safari 11.1, XCode 9.3 (9E145).


Update: I'm betting <rdar://problem/11489077> is the issue. Moving the app/extension to the Desktop causes it to work as expected.