Is it possible to see the source code of a Safari Extension?
Source of information:


Locate the extension. It should be living in your library folder. Note this is a hidden folder so in the finder use Command+Shift+G to put in this location ~/Library/Safari/Extensions.  Here you’ll see the Safari extensions you have installed. They have a .safariext file extension, but this is really just a xar file.

To extract the extension’s files, use this command (replacing the '/path/to' with the correct path and the 'extension.safariextz' with the correct name) xar -xf /path/to/extension.safariextz The extension will be extracted into a folder, with the source and resources contained within.

If you want to change something and then package it back up for
reinstallation, you can xar the folder back into a single file using xar -c -f output.safariextz extensionFolder.



I'm running 10.15.6 and these steps worked for me.
Since Safari 13, all extensions must be downloaded from the App Store as .app bundles with .appex files inside them. Both of them are built in Xcode thus you only get the final executable. So if the extension is not open source, you cannot see what's in the binary
A simple way to understand how the app and extension interact, see the following. (Note that it's an Xcode extension, not Safari. )

https://github.com/mapbox/XcodeClangFormat/blob/master/XcodeClangFormat/AppDelegate.m

https://github.com/mapbox/XcodeClangFormat/blob/master/clang-format/ClangFormatCommand.mm