safarisafari-app-extensionsafari-content-script

Safari App Extension content script not loaded on Safari error page?


When running a Safari App Extension, if Safari shows "Failed to open page", your content script isn't loaded. In this sort of scenario, it might be nice to redirect the user to a new url or suggestions page such as "did you mean...".

Is it possible to get a Safari App Extension's content script to load when a Safari error page is showing up?


Solution

  • No, it does not appear to be possible.

    Based on Apple's Safari App Extensions "About Permissions for Scripts and Style Sheets" documentation, I'm deducing that script injection only works on web content from http:// or https:// schemes, while error pages are loaded from local files.

    A URL pattern takes the form Scheme://Domain/Path. (...) Scheme can be http or https. (...) The asterisk character can be used anywhere in the domain or path, but not in the scheme.

    For reference, here's the path of a Safari 13 error page template.

    file:///Applications/Safari.app/Contents/Resources/en.lproj/StandardErrorPage.html