Skip to content

Commit d052c30

Browse files
committed
feat(browser): replace stealth with custom profile functionality
1 parent e02b374 commit d052c30

27 files changed

Lines changed: 1559 additions & 155 deletions

baidu/search.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func (baid *Baidu) isTimeout(page *rod.Page) bool {
7474
// It may return core.ErrCaptcha or core.ErrSearchTimeout.
7575
func (baid *Baidu) Search(ctx context.Context, query core.Query) (results []core.SearchResult, err error) {
7676
ctx = core.WithEngine(core.EnsureContext(ctx), baid.Name())
77+
ctx = core.WithProfileRegion(ctx, query.LangCode)
7778
ctx = core.WithQueryHash(ctx, core.QueryHashFromQuery(query))
7879
scoped := *baid
7980
scoped.logger = baid.logger.WithRequest(ctx)
@@ -177,6 +178,7 @@ func (baid *Baidu) Search(ctx context.Context, query core.Query) (results []core
177178
// results. It may return core.ErrCaptcha or core.ErrSearchTimeout.
178179
func (baid *Baidu) SearchImage(ctx context.Context, query core.Query) ([]core.SearchResult, error) {
179180
ctx = core.WithEngine(core.EnsureContext(ctx), baid.Name())
181+
ctx = core.WithProfileRegion(ctx, query.LangCode)
180182
ctx = core.WithQueryHash(ctx, core.QueryHashFromQuery(query))
181183
scoped := *baid
182184
scoped.logger = baid.logger.WithRequest(ctx)

bing/search.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func (bing *Bing) acceptCookies(ctx context.Context, page *rod.Page) error {
9898
// It may return core.ErrCaptcha or core.ErrSearchTimeout.
9999
func (bing *Bing) Search(ctx context.Context, query core.Query) (results []core.SearchResult, err error) {
100100
ctx = core.WithEngine(core.EnsureContext(ctx), bing.Name())
101+
ctx = core.WithProfileRegion(ctx, query.LangCode)
101102
ctx = core.WithQueryHash(ctx, core.QueryHashFromQuery(query))
102103
scoped := *bing
103104
scoped.logger = bing.logger.WithRequest(ctx)
@@ -274,6 +275,7 @@ type BingImageData struct {
274275
// results. It may return core.ErrCaptcha or core.ErrSearchTimeout.
275276
func (bing *Bing) SearchImage(ctx context.Context, query core.Query) ([]core.SearchResult, error) {
276277
ctx = core.WithEngine(core.EnsureContext(ctx), bing.Name())
278+
ctx = core.WithProfileRegion(ctx, query.LangCode)
277279
ctx = core.WithQueryHash(ctx, core.QueryHashFromQuery(query))
278280
scoped := *bing
279281
scoped.logger = bing.logger.WithRequest(ctx)

cmd/root.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ import (
77
"strings"
88

99
"github.com/karust/openserp/core"
10+
browserprofile "github.com/karust/openserp/core/browser"
1011
"github.com/sirupsen/logrus"
1112
"github.com/spf13/cobra"
1213
"github.com/spf13/pflag"
1314
"github.com/spf13/viper"
1415
)
1516

1617
const (
17-
version = "0.6.5"
18+
version = "0.6.6"
1819
defaultConfigFilename = "config"
1920
envPrefix = "OPENSERP"
2021
)
@@ -53,10 +54,10 @@ type ServerConfig struct {
5354
type AppConfig struct {
5455
Timeout int `mapstructure:"timeout"`
5556
BrowserPath string `mapstructure:"browser_path"`
57+
ProfilesJSON string `mapstructure:"profiles"`
5658
IsBrowserHead bool `mapstructure:"head"`
5759
IsLeaveHead bool `mapstructure:"leave_head"`
5860
IsLeakless bool `mapstructure:"leakless"`
59-
IsStealth bool `mapstructure:"stealth"`
6061
DebugEndpoints bool `mapstructure:"debug_endpoints"`
6162
LogFormat string `mapstructure:"log_format"`
6263
}
@@ -102,6 +103,7 @@ var flagToConfigKey = map[string]string{
102103
"timeout": "app.timeout",
103104
"config": "server.config_path",
104105
"browser-path": "app.browser_path",
106+
"profiles-json": "app.profiles",
105107
"verbose": "server.verbose",
106108
"debug": "server.debug",
107109
"head": "app.head",
@@ -110,7 +112,6 @@ var flagToConfigKey = map[string]string{
110112
"leave": "app.leave_head",
111113
"2captcha_key": "2captcha.apikey",
112114
"proxy": "proxies.global",
113-
"stealth": "app.stealth",
114115
"debug-endpoints": "app.debug_endpoints",
115116
"insecure": "server.insecure",
116117
"cache_ttl": "cache.ttl_seconds",
@@ -134,6 +135,9 @@ var RootCmd = &cobra.Command{
134135
if err != nil {
135136
return err
136137
}
138+
if err := browserprofile.LoadProfilesFromJSON(config.App.ProfilesJSON); err != nil {
139+
return fmt.Errorf("load app.profiles: %w", err)
140+
}
137141

138142
logFormat, err := core.NormalizeLogFormat(config.App.LogFormat)
139143
if err != nil {
@@ -316,10 +320,10 @@ func setConfigDefaults(v *viper.Viper) {
316320

317321
v.SetDefault("app.timeout", 30)
318322
v.SetDefault("app.browser_path", "")
323+
v.SetDefault("app.profiles", "")
319324
v.SetDefault("app.head", false)
320325
v.SetDefault("app.leave_head", false)
321326
v.SetDefault("app.leakless", false)
322-
v.SetDefault("app.stealth", false)
323327
v.SetDefault("app.debug_endpoints", false)
324328

325329
v.SetDefault("proxies.entries", []interface{}{})
@@ -348,6 +352,7 @@ func init() {
348352
RootCmd.PersistentFlags().IntVarP(&config.App.Timeout, "timeout", "t", 30, "Timeout to fail request")
349353
RootCmd.PersistentFlags().StringVarP(&config.Server.ConfigPath, "config", "c", "", "Configuration file path")
350354
RootCmd.PersistentFlags().StringVarP(&config.App.BrowserPath, "browser-path", "", "", "Custom browser binary path (Chrome/Chromium/Edge/Brave..)")
355+
RootCmd.PersistentFlags().StringVar(&config.App.ProfilesJSON, "profiles", "", "Path to browser profile catalog JSON")
351356
RootCmd.PersistentFlags().BoolVarP(&config.Server.IsVerbose, "verbose", "v", false, "Use verbose output")
352357
RootCmd.PersistentFlags().BoolVarP(&config.Server.IsDebug, "debug", "d", false, "Use debug output. Disable headless browser")
353358
RootCmd.PersistentFlags().BoolVarP(&config.App.IsBrowserHead, "head", "", false, "Enable browser UI")
@@ -356,7 +361,6 @@ func init() {
356361
RootCmd.PersistentFlags().BoolVarP(&config.App.IsLeaveHead, "leave", "", false, "Leave browser and tabs opened after search is made")
357362
RootCmd.PersistentFlags().StringVarP(&config.Config2Capcha.ApiKey, "2captcha_key", "", "", "2 captcha api key")
358363
RootCmd.PersistentFlags().StringVarP(&config.Proxies.Global, "proxy", "x", "", "Force a single proxy for all engines (same as proxies.global)")
359-
RootCmd.PersistentFlags().BoolVarP(&config.App.IsStealth, "stealth", "s", false, "Use stealth browser plugin")
360364
RootCmd.PersistentFlags().BoolVar(&config.App.DebugEndpoints, "debug-endpoints", false, "Enable debug-only HTTP endpoints")
361365
RootCmd.PersistentFlags().BoolVarP(&config.Server.Insecure, "insecure", "k", false, "Allow insecure TLS connections")
362366
RootCmd.PersistentFlags().IntVar(&config.Cache.TTLSeconds, "cache_ttl", 300, "Cache TTL in seconds (0 to disable)")

cmd/search.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ func searchBrowser(engineType string, query core.Query, browserProxyURL string,
117117
BrowserPath: config.App.BrowserPath,
118118
ProxyURL: browserProxyURL,
119119
Insecure: config.Server.Insecure,
120-
UseStealth: config.App.IsStealth,
121120
}
122121

123122
if config.Server.IsDebug {

cmd/serve.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ func buildFingerprintBrowserOptions() core.BrowserOpts {
132132
Timeout: time.Second * time.Duration(config.App.Timeout),
133133
BrowserPath: config.App.BrowserPath,
134134
Insecure: config.Server.Insecure,
135-
UseStealth: config.App.IsStealth,
136135
}
137136
if config.Server.IsDebug {
138137
opts.IsHeadless = false

config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ app:
1111
log_format: "text"
1212
timeout: 15 # Browser/search timeout in seconds
1313
browser_path: "" # Custom browser binary path (chrome/chromium/edge..)
14+
profiles: "" # Optional JSON file path overriding built-in browser profiles
1415
head: false # Show browser UI (headful mode)
1516
leakless: false # Force browser process cleanup after request
1617
leave_head: false # Keep tabs open after request for debugging
17-
stealth: false # Enable stealth browser plugin
1818

1919
proxies:
2020
# Force a single proxy for all engines.

0 commit comments

Comments
 (0)