How to use RemoteDebuggingPort method of launcher Package

Best Rod code snippet using launcher.RemoteDebuggingPort

launcher.go

Source:launcher.go Github

copy

Full Screen

...44 flags.Bin: {defaults.Bin},45 flags.Leakless: nil,46 flags.UserDataDir: {dir},47 // use random port by default48 flags.RemoteDebuggingPort: {defaults.Port},49 // enable headless by default50 flags.Headless: nil,51 // to disable the init blank window52 "no-first-run": nil,53 "no-startup-window": nil,54 // TODO: about the "site-per-process" see https://github.com/puppeteer/puppeteer/issues/254855 "disable-features": {"site-per-process", "TranslateUI"},56 "disable-background-networking": nil,57 "disable-background-timer-throttling": nil,58 "disable-backgrounding-occluded-windows": nil,59 "disable-breakpad": nil,60 "disable-client-side-phishing-detection": nil,61 "disable-component-extensions-with-background-pages": nil,62 "disable-default-apps": nil,63 "disable-dev-shm-usage": nil,64 "disable-hang-monitor": nil,65 "disable-ipc-flooding-protection": nil,66 "disable-popup-blocking": nil,67 "disable-prompt-on-repost": nil,68 "disable-renderer-backgrounding": nil,69 "disable-sync": nil,70 "enable-automation": nil,71 "enable-features": {"NetworkService", "NetworkServiceInProcess"},72 "force-color-profile": {"srgb"},73 "metrics-recording-only": nil,74 "use-mock-keychain": nil,75 }76 if defaults.Show {77 delete(defaultFlags, flags.Headless)78 }79 if defaults.Devtools {80 defaultFlags["auto-open-devtools-for-tabs"] = nil81 }82 if inContainer {83 defaultFlags[flags.NoSandbox] = nil84 }85 if defaults.Proxy != "" {86 defaultFlags[flags.ProxyServer] = []string{defaults.Proxy}87 }88 ctx, cancel := context.WithCancel(context.Background())89 return &Launcher{90 ctx: ctx,91 ctxCancel: cancel,92 Flags: defaultFlags,93 exit: make(chan struct{}),94 browser: NewBrowser(),95 parser: NewURLParser(),96 logger: ioutil.Discard,97 }98}99// NewUserMode is a preset to enable reusing current user data. Useful for automation of personal browser.100// If you see any error, it may because you can't launch debug port for existing browser, the solution is to101// completely close the running browser. Unfortunately, there's no API for rod to tell it automatically yet.102func NewUserMode() *Launcher {103 ctx, cancel := context.WithCancel(context.Background())104 bin, _ := LookPath()105 return &Launcher{106 ctx: ctx,107 ctxCancel: cancel,108 Flags: map[flags.Flag][]string{109 flags.RemoteDebuggingPort: {"37712"},110 "no-startup-window": nil,111 flags.Bin: {bin},112 },113 browser: NewBrowser(),114 exit: make(chan struct{}),115 parser: NewURLParser(),116 logger: ioutil.Discard,117 }118}119// NewAppMode is a preset to run the browser like a native application.120func NewAppMode(u string) *Launcher {121 l := New()122 l.Set(flags.App, u).123 Set(flags.Env, "GOOGLE_API_KEY=no").124 Headless(false).125 Delete("no-startup-window").126 Delete("enable-automation")127 return l128}129// Context sets the context130func (l *Launcher) Context(ctx context.Context) *Launcher {131 ctx, cancel := context.WithCancel(ctx)132 l.ctx = ctx133 l.parser.Context(ctx)134 l.ctxCancel = cancel135 return l136}137// Set a command line argument to launch the browser.138func (l *Launcher) Set(name flags.Flag, values ...string) *Launcher {139 if strings.Contains(string(name), "=") {140 panic("flag name should not contain '='")141 }142 l.Flags[l.normalizeFlag(name)] = values143 return l144}145// Get flag's first value146func (l *Launcher) Get(name flags.Flag) string {147 if list, has := l.GetFlags(name); has {148 return list[0]149 }150 return ""151}152// Has flag or not153func (l *Launcher) Has(name flags.Flag) bool {154 _, has := l.GetFlags(name)155 return has156}157// GetFlags from settings158func (l *Launcher) GetFlags(name flags.Flag) ([]string, bool) {159 flag, has := l.Flags[l.normalizeFlag(name)]160 return flag, has161}162// Append values to the flag163func (l *Launcher) Append(name flags.Flag, values ...string) *Launcher {164 flags, has := l.GetFlags(name)165 if !has {166 flags = []string{}167 }168 return l.Set(name, append(flags, values...)...)169}170// Delete a flag171func (l *Launcher) Delete(name flags.Flag) *Launcher {172 delete(l.Flags, l.normalizeFlag(name))173 return l174}175// Bin of the browser binary path to launch, if the path is not empty the auto download will be disabled176func (l *Launcher) Bin(path string) *Launcher {177 return l.Set(flags.Bin, path)178}179// Revision of the browser to auto download180func (l *Launcher) Revision(rev int) *Launcher {181 l.browser.Revision = rev182 return l183}184// Headless switch. Whether to run browser in headless mode. A mode without visible UI.185func (l *Launcher) Headless(enable bool) *Launcher {186 if enable {187 return l.Set(flags.Headless)188 }189 return l.Delete(flags.Headless)190}191// NoSandbox switch. Whether to run browser in no-sandbox mode.192// Linux users may face "running as root without --no-sandbox is not supported" in some Linux/Chrome combinations. This function helps switch mode easily.193// Be aware disabling sandbox is not trivial. Use at your own risk.194// Related doc: https://bugs.chromium.org/p/chromium/issues/detail?id=638180195func (l *Launcher) NoSandbox(enable bool) *Launcher {196 if enable {197 return l.Set(flags.NoSandbox)198 }199 return l.Delete(flags.NoSandbox)200}201// XVFB enables to run browser in by XVFB. Useful when you want to run headful mode on linux.202func (l *Launcher) XVFB(args ...string) *Launcher {203 return l.Set(flags.XVFB, args...)204}205// Leakless switch. If enabled, the browser will be force killed after the Go process exits.206// The doc of leakless: https://github.com/ysmood/leakless.207func (l *Launcher) Leakless(enable bool) *Launcher {208 if enable {209 return l.Set(flags.Leakless)210 }211 return l.Delete(flags.Leakless)212}213// Devtools switch to auto open devtools for each tab214func (l *Launcher) Devtools(autoOpenForTabs bool) *Launcher {215 if autoOpenForTabs {216 return l.Set("auto-open-devtools-for-tabs")217 }218 return l.Delete("auto-open-devtools-for-tabs")219}220// UserDataDir is where the browser will look for all of its state, such as cookie and cache.221// When set to empty, browser will use current OS home dir.222// Related doc: https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md223func (l *Launcher) UserDataDir(dir string) *Launcher {224 if dir == "" {225 l.Delete(flags.UserDataDir)226 } else {227 l.Set(flags.UserDataDir, dir)228 }229 return l230}231// ProfileDir is the browser profile the browser will use.232// When set to empty, the profile 'Default' is used.233// Related article: https://superuser.com/a/377195234func (l *Launcher) ProfileDir(dir string) *Launcher {235 if dir == "" {236 l.Delete("profile-directory")237 } else {238 l.Set("profile-directory", dir)239 }240 return l241}242// RemoteDebuggingPort to launch the browser. Zero for a random port. Zero is the default value.243// If it's not zero and the Launcher.Leakless is disabled, the launcher will try to reconnect to it first,244// if the reconnection fails it will launch a new browser.245func (l *Launcher) RemoteDebuggingPort(port int) *Launcher {246 return l.Set(flags.RemoteDebuggingPort, fmt.Sprintf("%d", port))247}248// Proxy switch. When disabled leakless will be disabled.249func (l *Launcher) Proxy(host string) *Launcher {250 return l.Set(flags.ProxyServer, host)251}252// WorkingDir to launch the browser process.253func (l *Launcher) WorkingDir(path string) *Launcher {254 return l.Set(flags.WorkingDir, path)255}256// Env to launch the browser process. The default value is os.Environ().257// Usually you use it to set the timezone env. Such as:258//259// Env(append(os.Environ(), "TZ=Asia/Tokyo")...)260func (l *Launcher) Env(env ...string) *Launcher {261 return l.Set(flags.Env, env...)262}263// StartURL to launch264func (l *Launcher) StartURL(u string) *Launcher {265 return l.Set("", u)266}267// FormatArgs returns the formated arg list for cli268func (l *Launcher) FormatArgs() []string {269 execArgs := []string{}270 for k, v := range l.Flags {271 if k == flags.Arguments {272 continue273 }274 if strings.HasPrefix(string(k), "rod-") {275 continue276 }277 // fix a bug of chrome, if path is not absolute chrome will hang278 if k == flags.UserDataDir {279 abs, err := filepath.Abs(v[0])280 utils.E(err)281 v[0] = abs282 }283 str := "--" + string(k)284 if v != nil {285 str += "=" + strings.Join(v, ",")286 }287 execArgs = append(execArgs, str)288 }289 execArgs = append(execArgs, l.Flags[flags.Arguments]...)290 sort.Strings(execArgs)291 return execArgs292}293// Logger to handle stdout and stderr from browser.294// For example, pipe all browser output to stdout: launcher.New().Logger(os.Stdout)295func (l *Launcher) Logger(w io.Writer) *Launcher {296 l.logger = w297 return l298}299// MustLaunch is similar to Launch300func (l *Launcher) MustLaunch() string {301 u, err := l.Launch()302 utils.E(err)303 return u304}305// Launch a standalone temp browser instance and returns the debug url.306// bin and profileDir are optional, set them to empty to use the default values.307// If you want to reuse sessions, such as cookies, set the UserDataDir to the same location.308func (l *Launcher) Launch() (string, error) {309 defer l.ctxCancel()310 bin, err := l.getBin()311 if err != nil {312 return "", err313 }314 var ll *leakless.Launcher315 var cmd *exec.Cmd316 if l.Has(flags.Leakless) && leakless.Support() {317 ll = leakless.New()318 cmd = ll.Command(bin, l.FormatArgs()...)319 } else {320 port := l.Get(flags.RemoteDebuggingPort)321 u, err := ResolveURL(port)322 if err == nil {323 return u, nil324 }325 cmd = exec.Command(bin, l.FormatArgs()...)326 }327 l.setupCmd(cmd)328 err = cmd.Start()329 if err != nil {330 return "", err331 }332 if ll == nil {333 l.pid = cmd.Process.Pid334 } else {...

Full Screen

Full Screen

launcher_test.go

Source:launcher_test.go Github

copy

Full Screen

...115 l = l.Context(g.Context()).Delete("test").Bin("").116 Revision(launcher.RevisionDefault).117 Logger(ioutil.Discard).118 Leakless(false).Leakless(true).119 Headless(false).Headless(true).RemoteDebuggingPort(port).120 NoSandbox(true).NoSandbox(false).121 Devtools(true).Devtools(false).122 StartURL("about:blank").123 Proxy("test.com").124 UserDataDir("test").UserDataDir(dir).125 WorkingDir("").126 Env(append(os.Environ(), "TZ=Asia/Tokyo")...)127 g.Eq(l.FormatArgs(), []string /* len=6 cap=8 */ {128 "--headless",129 `--no-startup-window`, /* len=19 */130 `--proxy-server=test.com`, /* len=23 */131 `--remote-debugging-port=58472`, /* len=29 */132 "--test-append=a",133 "about:blank",134 })135 url := l.MustLaunch()136 g.Eq(url, launcher.NewUserMode().RemoteDebuggingPort(port).MustLaunch())137}138func TestUserModeErr(t *testing.T) {139 g := setup(t)140 _, err := launcher.NewUserMode().RemoteDebuggingPort(48277).Bin("not-exists").Launch()141 g.Err(err)142 _, err = launcher.NewUserMode().RemoteDebuggingPort(58217).Bin("echo").Launch()143 g.Err(err)144}145func TestAppMode(t *testing.T) {146 g := setup(t)147 l := launcher.NewAppMode("http://example.com")148 g.Eq(l.Get(flags.App), "http://example.com")149}150func TestGetWebSocketDebuggerURLErr(t *testing.T) {151 g := setup(t)152 _, err := launcher.ResolveURL("1://")153 g.Err(err)154}155func TestLaunchErr(t *testing.T) {156 g := setup(t)...

Full Screen

Full Screen

RemoteDebuggingPort

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 const (4 opts := []selenium.ServiceOption{5 }6 selenium.SetDebug(true)7 seleniumPort, err := selenium.FreePort()8 if err != nil {9 }10 service, err := selenium.NewChromeDriverService(chromeDriverPath, seleniumPort, opts...)11 if err != nil {12 panic(err)13 }14 defer service.Stop()15 caps := selenium.Capabilities{"browserName": "chrome"}16 caps.AddChrome(chrome.Capabilities{17 Args: []string{18 },19 })20 if err != nil {21 panic(err)22 }23 defer wd.Quit()24 panic(err)25 }26 if err := wd.WaitWithTimeout(selenium.Condition("function() { return document.readyState == 'complete

Full Screen

Full Screen

RemoteDebuggingPort

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 launcher := agouti.ChromeDriver(4 agouti.ChromeOptions("args", []string{5 }),6 port, err := launcher.RemoteDebuggingPort()7 if err != nil {8 log.Fatal(err)9 }10 fmt.Println(port)11}

Full Screen

Full Screen

RemoteDebuggingPort

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 launcher := godet.NewLauncher()4 launcher.Set("remote-debugging-port", "9222")5 err := launcher.Start()6 if err != nil {7 fmt.Println(err)8 }9 defer launcher.Kill()10 fmt.Println("Chrome is running on port", launcher.RemoteDebuggingPort())11}

Full Screen

Full Screen

RemoteDebuggingPort

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 launcher := geckodriver.NewLauncher()4 launcher.Start()5 fmt.Println(launcher.RemoteDebuggingPort())6 launcher.Stop()7}8import (9func main() {10 launcher := geckodriver.NewLauncher()11 launcher.SetPreference("browser.startup.homepage", "

Full Screen

Full Screen

RemoteDebuggingPort

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 l, err := runner.NewLauncher()4 if err != nil {5 panic(err)6 }7 port, err := l.Allocate()8 if err != nil {9 panic(err)10 }11 if err := l.Run(); err != nil {12 panic(err)13 }14 fmt.Println(l.RemoteDebuggingPort())15 if err := l.Release(port); err != nil {16 panic(err)17 }18 if err := l.Kill(); err != nil {19 panic(err)20 }21}22import (23func main() {24 l, err := runner.NewLauncher()25 if err != nil {26 panic(err)27 }28 port, err := l.Allocate()29 if err != nil {30 panic(err)31 }32 if err := l.Run(); err != nil {33 panic(err)34 }35 fmt.Println(l.RemoteDebuggingPort())36 if err := l.Release(port); err != nil {37 panic(err)38 }39 if err := l.Kill(); err != nil {40 panic(err)41 }42}43import (44func main() {45 l, err := runner.NewLauncher()46 if err != nil {47 panic(err)48 }49 port, err := l.Allocate()50 if err != nil {51 panic(err)

Full Screen

Full Screen

RemoteDebuggingPort

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 launcher := godet.NewLauncher()4 launcher.Start()5 defer launcher.Kill()6 remoteDebuggerPort := launcher.RemoteDebuggingPort()7 fmt.Println(remoteDebuggerPort)8 debugger := godet.Connect("

Full Screen

Full Screen

RemoteDebuggingPort

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 err := cmd.Start()4 if err != nil {5 log.Fatal(err)6 }7 time.Sleep(5 * time.Second)8 client := http.Client{}9 if err != nil {10 log.Fatal(err)11 }12 resp, err := client.Do(req)13 if err != nil {14 log.Fatal(err)15 }16 defer resp.Body.Close()17 fmt.Println(resp.StatusCode)18 fmt.Println(resp.Body)19}20&{0xc0000c8a80}

Full Screen

Full Screen

RemoteDebuggingPort

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 launcher := godet.NewLauncher()4 launcher.Set("remote-debugging-port", "9222")5 launcher.Set("headless", "")6 launcher.Set("disable-gpu", "")7 launcher.Set("window-size", "1920,1080")8 launcher.Set("user-data-dir", "C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\User Data")9 launcher.Set("disable-web-security", "")10 launcher.Set("allow-running-insecure-content", "")11 launcher.Set("disable-features", "IsolateOrigins,site-per-process")12 launcher.Set("enable-features", "NetworkService,NetworkServiceInProcess")13 launcher.Set("disable-web-security", "")14 launcher.Set("disable-site-isolation-trials", "")15 launcher.Set("disable-features", "SameSiteByDefaultCookies,CookiesWithoutSameSiteMustBeSecure,SameSiteDefaultChecksMethodRigorously")16 launcher.Set("disable-features", "IsolateOrigins,site-per-process")17 launcher.Set("enable-features", "NetworkService,NetworkServiceInProcess")18 launcher.Set("disable-features", "IsolateOrigins,site-per-process")19 launcher.Set("enable-features", "NetworkService,NetworkServiceInProcess")20 launcher.Set("disable-features", "IsolateOrigins,site-per-process")21 launcher.Set("enable-features", "NetworkService,NetworkServiceInProcess")22 launcher.Set("disable-features", "IsolateOrigins,site-per-process")23 launcher.Set("enable-features", "NetworkService,NetworkServiceInProcess")24 launcher.Set("disable-features", "IsolateOrigins,site-per-process")25 launcher.Set("enable-features", "NetworkService,NetworkServiceInProcess")26 launcher.Set("disable-features", "IsolateOrigins,site-per-process")27 launcher.Set("enable-features", "NetworkService,NetworkServiceInProcess")28 launcher.Set("disable-features", "IsolateOrigins,site-per-process")29 launcher.Set("enable-features", "NetworkService,NetworkServiceInProcess")30 launcher.Set("disable-features", "IsolateOrigins,site-per-process")31 launcher.Set("enable-features

Full Screen

Full Screen

RemoteDebuggingPort

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 cmd := exec.Command("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "--remote-debugging-port=9222")4 cmd.Start()5 time.Sleep(2 * time.Second)6 port, err := RemoteDebuggingPort()7 if err != nil {8 fmt.Println(err)9 }10 fmt.Println(port)11 _, err = net.Dial("tcp", "

Full Screen

Full Screen

RemoteDebuggingPort

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 l := godet.NewLauncher()4 port, err := l.Start()5 if err != nil {6 panic(err)7 }8 remote, err := godet.Connect(fmt.Sprintf("

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful