rod icon indicating copy to clipboard operation
rod copied to clipboard

Add FreeBSD support

Open DtxdF opened this issue 1 year ago • 0 comments

Rod Version: v0.112.2

Hi,

I'm porting vhs to FreeBSD and when I run it i get the following error:

# vhs < cassette.tape
[launcher.Browser]2023/03/07 10:34:34 try to find the fastest host to download the browser binary
[launcher.Browser]2023/03/07 10:34:34 check https://storage.googleapis.com/chromium-browser-snapshots//1033860/
[launcher.Browser]2023/03/07 10:34:34 check https://registry.npmmirror.com/-/binary/chromium-browser-snapshots//1033860/
[launcher.Browser]2023/03/07 10:34:34 check https://playwright.azureedge.net/builds/chromium/1033860/chromium-linux-arm64.zip
panic: Can't find a browser binary for your OS, the doc might help https://go-rod.github.io/#/compatibility?id=os

goroutine 1 [running]:
github.com/go-rod/rod/lib/utils.glob..func2({0xdbe940?, 0xc0002ad400?})
        github.com/go-rod/rod/lib/utils/utils.go:60 +0x25
github.com/go-rod/rod/lib/utils.E(...)
        github.com/go-rod/rod/lib/utils/utils.go:66
github.com/go-rod/rod/lib/launcher.(*Launcher).MustLaunch(0xc0003280e0?)
        github.com/go-rod/rod/lib/launcher/launcher.go:351 +0x67
main.New()
        github.com/charmbracelet/vhs/vhs.go:91 +0x2e5
main.Evaluate({0x1238598, 0xc00002e940}, {0xc0004d4000, 0x2a}, {0x1233e00, 0xc0000b0008}, {0xc0005ebcd8, 0x1, 0x0?})
        github.com/charmbracelet/vhs/evaluator.go:25 +0x1a5
main.glob..func1(0x1832f40, {0x1884a78, 0x0, 0x0?})
        github.com/charmbracelet/vhs/main.go:67 +0x245
github.com/spf13/cobra.(*Command).execute(0x1832f40, {0xc000090030, 0x0, 0x0})
        github.com/spf13/cobra/command.go:916 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0x1832f40)
        github.com/spf13/cobra/command.go:1044 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra/command.go:968
github.com/spf13/cobra.(*Command).ExecuteContext(...)
        github.com/spf13/cobra/command.go:961
main.main()
        github.com/charmbracelet/vhs/main.go:186 +0xf1

I read the vhs source code to find out whtat the error is, and found that it uses launcher.LookPath(), a go-rod function in lib/launcher/browser.go, so I just add another entry to point it to the chromium path for FreeBSD.

--- vendor/github.com/go-rod/rod/lib/launcher/browser.go.orig   2023-03-07 14:57:56 UTC
+++ vendor/github.com/go-rod/rod/lib/launcher/browser.go
@@ -303,6 +303,10 @@ func LookPath() (found string, has bool) {
                        "/usr/bin/chromium-browser",
                        "/snap/bin/chromium",
                },
+               "freebsd": {
+                       "chrome",
+                       "ungoogled-chromium",
+               },
                "windows": append([]string{"chrome", "edge"}, expandWindowsExePaths(
                        `Google\Chrome\Application\chrome.exe`,
                        `Chromium\Application\chrome.exe`,

The above is the patch used by the port. In addition, I have added and tested ungoogled-chromium with vhs. Of course, I see that to add full support, it is necessary to add FreeBSD on HostGoogle(), HostNPM(), HostPlaywright() and so on, but I think it is woth it only for users who install VHS or any go program that uses go-rod using go-install, or to avoid patching go-rod every time a software that use it is ported to FreeBSD.

DtxdF avatar Mar 08 '23 13:03 DtxdF