mirror of
https://github.com/tenox7/wrp.git
synced 2026-07-08 18:06:35 +00:00
auto detect browser
This commit is contained in:
6
ismap.go
6
ismap.go
@@ -94,8 +94,14 @@ func chromedpStart() (context.CancelFunc, context.CancelFunc) {
|
||||
if *userAgent != "" {
|
||||
opts = append(opts, chromedp.UserAgent(*userAgent))
|
||||
}
|
||||
if *browserPath == "" {
|
||||
*browserPath = findBrowser()
|
||||
}
|
||||
if *browserPath != "" {
|
||||
log.Printf("Using browser: %s", *browserPath)
|
||||
opts = append(opts, chromedp.ExecPath(*browserPath))
|
||||
} else {
|
||||
log.Printf("No browser detected, falling back to chromedp default lookup")
|
||||
}
|
||||
if *userDataDir != "" {
|
||||
opts = append(opts, chromedp.UserDataDir(*userDataDir))
|
||||
|
||||
70
util.go
70
util.go
@@ -8,6 +8,10 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -72,6 +76,72 @@ func asciify(s []byte) []byte {
|
||||
return a
|
||||
}
|
||||
|
||||
func findBrowser() string {
|
||||
var paths []string
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
paths = []string{
|
||||
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
||||
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
||||
"/Applications/Brave Browser.app/Contents/MacOS/Brave Browser",
|
||||
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge",
|
||||
"/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
|
||||
"/Applications/Brave Browser Beta.app/Contents/MacOS/Brave Browser Beta",
|
||||
"/Applications/Brave Browser Nightly.app/Contents/MacOS/Brave Browser Nightly",
|
||||
"/Applications/Vivaldi.app/Contents/MacOS/Vivaldi",
|
||||
"/Applications/Arc.app/Contents/MacOS/Arc",
|
||||
}
|
||||
case "windows":
|
||||
pf := os.Getenv("ProgramFiles")
|
||||
pfx86 := os.Getenv("ProgramFiles(x86)")
|
||||
lad := os.Getenv("LOCALAPPDATA")
|
||||
paths = []string{
|
||||
filepath.Join(pf, `Google\Chrome\Application\chrome.exe`),
|
||||
filepath.Join(pfx86, `Google\Chrome\Application\chrome.exe`),
|
||||
filepath.Join(lad, `Google\Chrome\Application\chrome.exe`),
|
||||
filepath.Join(pf, `BraveSoftware\Brave-Browser\Application\brave.exe`),
|
||||
filepath.Join(pfx86, `BraveSoftware\Brave-Browser\Application\brave.exe`),
|
||||
filepath.Join(lad, `BraveSoftware\Brave-Browser\Application\brave.exe`),
|
||||
filepath.Join(pf, `Chromium\Application\chrome.exe`),
|
||||
filepath.Join(lad, `Chromium\Application\chrome.exe`),
|
||||
filepath.Join(pf, `Microsoft\Edge\Application\msedge.exe`),
|
||||
filepath.Join(pfx86, `Microsoft\Edge\Application\msedge.exe`),
|
||||
filepath.Join(pf, `Vivaldi\Application\vivaldi.exe`),
|
||||
}
|
||||
default:
|
||||
paths = []string{
|
||||
"/usr/bin/google-chrome",
|
||||
"/usr/bin/google-chrome-stable",
|
||||
"/usr/bin/chromium",
|
||||
"/usr/bin/chromium-browser",
|
||||
"/usr/bin/brave-browser",
|
||||
"/usr/bin/brave-browser-stable",
|
||||
"/usr/bin/brave",
|
||||
"/usr/bin/microsoft-edge",
|
||||
"/usr/bin/vivaldi",
|
||||
"/snap/bin/chromium",
|
||||
"/snap/bin/brave",
|
||||
"/opt/brave.com/brave/brave",
|
||||
"/opt/google/chrome/chrome",
|
||||
"/opt/vivaldi/vivaldi",
|
||||
"/usr/local/bin/chrome",
|
||||
"/usr/local/bin/chromium",
|
||||
"/usr/local/bin/brave",
|
||||
}
|
||||
}
|
||||
for _, p := range paths {
|
||||
if _, err := os.Stat(p); err == nil {
|
||||
return p
|
||||
}
|
||||
}
|
||||
for _, n := range []string{"google-chrome", "google-chrome-stable", "chromium", "chromium-browser", "brave-browser", "brave", "microsoft-edge", "vivaldi", "chrome"} {
|
||||
if p, err := exec.LookPath(n); err == nil {
|
||||
return p
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func fetchJnrbsnUserAgent() string {
|
||||
client := &http.Client{Timeout: 5 * time.Second}
|
||||
resp, err := client.Get("https://jnrbsn.github.io/user-agents/user-agents.json")
|
||||
|
||||
Reference in New Issue
Block a user