How to use LauncherBase method of PuppeteerSharp.LauncherBase class

Best Puppeteer-sharp code snippet using PuppeteerSharp.LauncherBase.LauncherBase

LauncherBase.cs

Source:LauncherBase.cs Github

copy

Full Screen

...12 /// <summary>13 /// Represents a Base process and any associated temporary user data directory that have created14 /// by Puppeteer and therefore must be cleaned up when no longer needed.15 /// </summary>16 public class LauncherBase : IDisposable17 {18 #region Instance fields19 private readonly LaunchOptions _options;20 private readonly TaskCompletionSource<string> _startCompletionSource = new TaskCompletionSource<string>(TaskCreationOptions.RunContinuationsAsynchronously);21 private readonly TaskCompletionSource<bool> _exitCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);22 private State _currentState = State.Initial;23 #endregion24 #region Constructor25 /// <summary>26 /// Creates a new <see cref="LauncherBase"/> instance.27 /// </summary>28 /// <param name="executable">Full path of executable.</param>29 /// <param name="options">Options for launching Base.</param>30 /// <param name="loggerFactory">Logger factory</param>31 public LauncherBase(string executable, LaunchOptions options)32 {33 _options = options;34 Process = new Process35 {36 EnableRaisingEvents = true37 };38 Process.StartInfo.UseShellExecute = false;39 Process.StartInfo.FileName = executable;40 Process.StartInfo.RedirectStandardError = true;41 SetEnvVariables(Process.StartInfo.Environment, options.Env, Environment.GetEnvironmentVariables());42 if (options.DumpIO)43 {44 Process.ErrorDataReceived += (sender, e) => Console.Error.WriteLine(e.Data);45 }46 }47 #endregion48 #region Dispose49 /// <summary>50 /// Finalizer.51 /// </summary>52 ~LauncherBase()53 {54 Dispose(false);55 }56 /// <inheritdoc />57 public void Dispose()58 {59 Dispose(true);60 GC.SuppressFinalize(this);61 }62 /// <summary>63 /// Disposes Base process and any temporary user directory.64 /// </summary>65 /// <param name="disposing">Indicates whether disposal was initiated by <see cref="Dispose()"/> operation.</param>66 protected virtual void Dispose(bool disposing) => _currentState.Dispose(this);67 #endregion68 #region Properties69 /// <summary>70 /// Gets Base process details.71 /// </summary>72 public Process Process { get; }73 /// <summary>74 /// Gets Base endpoint.75 /// </summary>76 public string EndPoint => _startCompletionSource.Task.IsCompleted77 ? _startCompletionSource.Task.Result78 : null;79 /// <summary>80 /// Indicates whether Base process is exiting.81 /// </summary>82 public bool IsExiting => _currentState.IsExiting;83 /// <summary>84 /// Indicates whether Base process has exited.85 /// </summary>86 public bool HasExited => _currentState.IsExited;87 internal TempDirectory TempUserDataDir { get; set; }88 /// <summary>89 /// Gets Base process current state.90 /// </summary>91 protected State CurrentState { get => _currentState; }92 #endregion93 #region Public methods94 /// <summary>95 /// Asynchronously starts Base process.96 /// </summary>97 /// <returns></returns>98 public Task StartAsync() => _currentState.StartAsync(this);99 /// <summary>100 /// Asynchronously waits for graceful Base process exit within a given timeout period.101 /// Kills the Base process if it has not exited within this period.102 /// </summary>103 /// <param name="timeout">The maximum waiting time for a graceful process exit.</param>104 /// <returns></returns>105 public Task EnsureExitAsync(TimeSpan? timeout) => timeout.HasValue106 ? _currentState.ExitAsync(this, timeout.Value)107 : _currentState.KillAsync(this);108 /// <summary>109 /// Asynchronously kills Base process.110 /// </summary>111 /// <returns></returns>112 public Task KillAsync() => _currentState.KillAsync(this);113 /// <summary>114 /// Waits for Base process exit within a given timeout.115 /// </summary>116 /// <param name="timeout">The maximum wait period.</param>117 /// <returns><c>true</c> if Base process has exited within the given <paramref name="timeout"/>,118 /// or <c>false</c> otherwise.</returns>119 public async Task<bool> WaitForExitAsync(TimeSpan? timeout)120 {121 if (timeout.HasValue)122 {123 bool taskCompleted = true;124 await _exitCompletionSource.Task.WithTimeout(125 () =>126 {127 taskCompleted = false;128 }, timeout.Value).ConfigureAwait(false);129 return taskCompleted;130 }131 await _exitCompletionSource.Task.ConfigureAwait(false);132 return true;133 }134 #endregion135 #region Private methods136 /// <summary>137 /// Set Env Variables138 /// </summary>139 /// <param name="environment">The environment.</param>140 /// <param name="customEnv">The customEnv.</param>141 /// <param name="realEnv">The realEnv.</param>142 protected static void SetEnvVariables(IDictionary<string, string> environment, IDictionary<string, string> customEnv, IDictionary realEnv)143 {144 foreach (DictionaryEntry item in realEnv)145 {146 environment[item.Key.ToString()] = item.Value.ToString();147 }148 if (customEnv != null)149 {150 foreach (var item in customEnv)151 {152 environment[item.Key] = item.Value;153 }154 }155 }156 #endregion157 #region State machine158 /// <summary>159 /// Represents state machine for Base process instances. The happy path runs along the160 /// following state transitions: <see cref="Initial"/>161 /// -> <see cref="Starting"/>162 /// -> <see cref="Started"/>163 /// -> <see cref="Exiting"/>164 /// -> <see cref="Exited"/>.165 /// -> <see cref="Disposed"/>.166 /// </summary>167 /// <remarks>168 /// <para>169 /// This state machine implements the following state transitions:170 /// <code>171 /// State Event Target State Action172 /// ======== =================== ============ ==========================================================173 /// Initial --StartAsync------> Starting Start process and wait for endpoint174 /// Initial --ExitAsync-------> Exited Cleanup temp user data175 /// Initial --KillAsync-------> Exited Cleanup temp user data176 /// Initial --Dispose---------> Disposed Cleanup temp user data177 /// Starting --StartAsync------> Starting -178 /// Starting --ExitAsync-------> Exiting Wait for process exit179 /// Starting --KillAsync-------> Killing Kill process180 /// Starting --Dispose---------> Disposed Kill process; Cleanup temp user data; throw ObjectDisposedException on outstanding async operations;181 /// Starting --endpoint ready--> Started Complete StartAsync successfully; Log process start182 /// Starting --process exit----> Exited Complete StartAsync with exception; Cleanup temp user data183 /// Started --StartAsync------> Started -184 /// Started --EnsureExitAsync-> Exiting Start exit timer; Log process exit185 /// Started --KillAsync-------> Killing Kill process; Log process exit186 /// Started --Dispose---------> Disposed Kill process; Log process exit; Cleanup temp user data; throw ObjectDisposedException on outstanding async operations;187 /// Started --process exit----> Exited Log process exit; Cleanup temp user data188 /// Exiting --StartAsync------> Exiting - (StartAsync throws InvalidOperationException)189 /// Exiting --ExitAsync-------> Exiting -190 /// Exiting --KillAsync-------> Killing Kill process191 /// Exiting --Dispose---------> Disposed Kill process; Cleanup temp user data; throw ObjectDisposedException on outstanding async operations;192 /// Exiting --exit timeout----> Killing Kill process193 /// Exiting --process exit----> Exited Cleanup temp user data; complete outstanding async operations;194 /// Killing --StartAsync------> Killing - (StartAsync throws InvalidOperationException)195 /// Killing --KillAsync-------> Killing -196 /// Killing --Dispose---------> Disposed Cleanup temp user data; throw ObjectDisposedException on outstanding async operations;197 /// Killing --process exit----> Exited Cleanup temp user data; complete outstanding async operations;198 /// Exited --StartAsync------> Killing - (StartAsync throws InvalidOperationException)199 /// Exited --KillAsync-------> Exited -200 /// Exited --Dispose---------> Disposed -201 /// Disposed --StartAsync------> Disposed -202 /// Disposed --KillAsync-------> Disposed -203 /// Disposed --Dispose---------> Disposed -204 /// </code>205 /// </para>206 /// </remarks>207 protected abstract class State208 {209 #region Predefined states210 /// <summary>211 /// Set initial state.212 /// </summary>213 public static readonly State Initial = new InitialState();214 private static readonly StartingState Starting = new StartingState();215 private static readonly StartedState Started = new StartedState();216 private static readonly ExitingState Exiting = new ExitingState();217 private static readonly KillingState Killing = new KillingState();218 private static readonly ExitedState Exited = new ExitedState();219 private static readonly DisposedState Disposed = new DisposedState();220 #endregion221 #region Properties222 /// <summary>223 /// Get If process exists.224 /// </summary>225 public bool IsExiting => this == Killing || this == Exiting;226 /// <summary>227 /// Get If process is exited.228 /// </summary>229 public bool IsExited => this == Exited || this == Disposed;230 #endregion231 #region Methods232 /// <summary>233 /// Attempts thread-safe transitions from a given state to this state.234 /// </summary>235 /// <param name="p">The Base process</param>236 /// <param name="fromState">The state from which state transition takes place</param>237 /// <returns>Returns <c>true</c> if transition is successful, or <c>false</c> if transition238 /// cannot be made because current state does not equal <paramref name="fromState"/>.</returns>239 protected bool TryEnter(LauncherBase p, State fromState)240 {241 if (Interlocked.CompareExchange(ref p._currentState, this, fromState) == fromState)242 {243 fromState.Leave(p);244 return true;245 }246 return false;247 }248 /// <summary>249 /// Notifies that state machine is about to transition to another state.250 /// </summary>251 /// <param name="p">The Base process</param>252 protected virtual void Leave(LauncherBase p)253 {254 }255 /// <summary>256 /// Handles process start request.257 /// </summary>258 /// <param name="p">The Base process</param>259 /// <returns></returns>260 public virtual Task StartAsync(LauncherBase p) => Task.FromException(InvalidOperation("start"));261 /// <summary>262 /// Handles process exit request.263 /// </summary>264 /// <param name="p">The Base process</param>265 /// <param name="timeout">The maximum waiting time for a graceful process exit.</param>266 /// <returns></returns>267 public virtual Task ExitAsync(LauncherBase p, TimeSpan timeout) => Task.FromException(InvalidOperation("exit"));268 /// <summary>269 /// Handles process kill request.270 /// </summary>271 /// <param name="p">The Base process</param>272 /// <returns></returns>273 public virtual Task KillAsync(LauncherBase p) => Task.FromException(InvalidOperation("kill"));274 /// <summary>275 /// Handles wait for process exit request.276 /// </summary>277 /// <param name="p">The Base process</param>278 /// <returns></returns>279 public virtual Task WaitForExitAsync(LauncherBase p) => p._exitCompletionSource.Task;280 /// <summary>281 /// Handles disposal of process and temporary user directory282 /// </summary>283 /// <param name="p"></param>284 public virtual void Dispose(LauncherBase p) => Disposed.EnterFrom(p, this);285 /// <inheritdoc />286 public override string ToString()287 {288 string name = GetType().Name;289 return name.Substring(0, name.Length - "State".Length);290 }291 private Exception InvalidOperation(string operationName)292 => new InvalidOperationException($"Cannot {operationName} in state {this}");293 /// <summary>294 /// Kills process if it is still alive.295 /// </summary>296 /// <param name="p"></param>297 private static void Kill(LauncherBase p)298 {299 try300 {301 if (!p.Process.HasExited)302 {303 p.Process.Kill();304 }305 }306 catch (InvalidOperationException)307 {308 // Ignore309 }310 }311 #endregion312 #region Concrete state classes313 private class InitialState : State314 {315 public override Task StartAsync(LauncherBase p) => Starting.EnterFromAsync(p, this);316 public override Task ExitAsync(LauncherBase p, TimeSpan timeout)317 {318 Exited.EnterFrom(p, this);319 return Task.CompletedTask;320 }321 public override Task KillAsync(LauncherBase p)322 {323 Exited.EnterFrom(p, this);324 return Task.CompletedTask;325 }326 public override Task WaitForExitAsync(LauncherBase p) => Task.FromException(InvalidOperation("wait for exit"));327 }328 private class StartingState : State329 {330 public Task EnterFromAsync(LauncherBase p, State fromState)331 {332 if (!TryEnter(p, fromState))333 {334 // Delegate StartAsync to current state, because it has already changed since335 // transition to this state was initiated.336 return p._currentState.StartAsync(p);337 }338 return StartCoreAsync(p);339 }340 public override Task StartAsync(LauncherBase p) => p._startCompletionSource.Task;341 public override Task ExitAsync(LauncherBase p, TimeSpan timeout) => Exiting.EnterFromAsync(p, this, timeout);342 public override Task KillAsync(LauncherBase p) => Killing.EnterFromAsync(p, this);343 public override void Dispose(LauncherBase p)344 {345 p._startCompletionSource.TrySetException(new ObjectDisposedException(p.ToString()));346 base.Dispose(p);347 }348 private async Task StartCoreAsync(LauncherBase p)349 {350 var output = new StringBuilder();351 void OnProcessDataReceivedWhileStarting(object sender, DataReceivedEventArgs e)352 {353 if (e.Data != null)354 {355 output.AppendLine(e.Data);356 var match = Regex.Match(e.Data, "^DevTools listening on (ws:\\/\\/.*)");357 if (match.Success)358 {359 p._startCompletionSource.TrySetResult(match.Groups[1].Value);360 }361 }362 }363 void OnProcessExitedWhileStarting(object sender, EventArgs e)364 => p._startCompletionSource.TrySetException(new ProcessException($"Failed to launch Base! {output}"));365 void OnProcessExited(object sender, EventArgs e) => Exited.EnterFrom(p, p._currentState);366 p.Process.ErrorDataReceived += OnProcessDataReceivedWhileStarting;367 p.Process.Exited += OnProcessExitedWhileStarting;368 p.Process.Exited += OnProcessExited;369 CancellationTokenSource cts = null;370 try371 {372 p.Process.Start();373 await Started.EnterFromAsync(p, this).ConfigureAwait(false);374 p.Process.BeginErrorReadLine();375 int timeout = p._options.Timeout;376 if (timeout > 0)377 {378 cts = new CancellationTokenSource(timeout);379 cts.Token.Register(() => p._startCompletionSource.TrySetException(380 new ProcessException($"Timed out after {timeout} ms while trying to connect to Base!")));381 }382 try383 {384 await p._startCompletionSource.Task.ConfigureAwait(false);385 await Started.EnterFromAsync(p, this).ConfigureAwait(false);386 }387 catch388 {389 await Killing.EnterFromAsync(p, this).ConfigureAwait(false);390 throw;391 }392 }393 finally394 {395 cts?.Dispose();396 p.Process.Exited -= OnProcessExitedWhileStarting;397 p.Process.ErrorDataReceived -= OnProcessDataReceivedWhileStarting;398 }399 }400 }401 private class StartedState : State402 {403 public Task EnterFromAsync(LauncherBase p, State fromState)404 {405 if (TryEnter(p, fromState))406 {407 }408 return Task.CompletedTask;409 }410 protected override void Leave(LauncherBase p) { }411 public override Task StartAsync(LauncherBase p) => Task.CompletedTask;412 public override Task ExitAsync(LauncherBase p, TimeSpan timeout) => Exiting.EnterFromAsync(p, this, timeout);413 public override Task KillAsync(LauncherBase p) => Killing.EnterFromAsync(p, this);414 }415 private class ExitingState : State416 {417 public Task EnterFromAsync(LauncherBase p, State fromState, TimeSpan timeout)418 => !TryEnter(p, fromState) ? p._currentState.ExitAsync(p, timeout) : ExitAsync(p, timeout);419 public override async Task ExitAsync(LauncherBase p, TimeSpan timeout)420 {421 var waitForExitTask = WaitForExitAsync(p);422 await waitForExitTask.WithTimeout(423 async () =>424 {425 await Killing.EnterFromAsync(p, this).ConfigureAwait(false);426 await waitForExitTask.ConfigureAwait(false);427 },428 timeout,429 CancellationToken.None).ConfigureAwait(false);430 }431 public override Task KillAsync(LauncherBase p) => Killing.EnterFromAsync(p, this);432 }433 private class KillingState : State434 {435 public async Task EnterFromAsync(LauncherBase p, State fromState)436 {437 if (!TryEnter(p, fromState))438 {439 // Delegate KillAsync to current state, because it has already changed since440 // transition to this state was initiated.441 await p._currentState.KillAsync(p).ConfigureAwait(false);442 }443 try444 {445 if (!p.Process.HasExited)446 {447 p.Process.Kill();448 }449 }450 catch (InvalidOperationException)451 {452 // Ignore453 return;454 }455 await WaitForExitAsync(p).ConfigureAwait(false);456 }457 public override Task ExitAsync(LauncherBase p, TimeSpan timeout) => WaitForExitAsync(p);458 public override Task KillAsync(LauncherBase p) => WaitForExitAsync(p);459 }460 private class ExitedState : State461 {462 public void EnterFrom(LauncherBase p, State fromState)463 {464 while (!TryEnter(p, fromState))465 {466 // Current state has changed since transition to this state was requested.467 // Therefore retry transition to this state from the current state. This ensures468 // that Leave() operation of current state is properly called.469 fromState = p._currentState;470 if (fromState == this)471 {472 return;473 }474 }475 p._exitCompletionSource.TrySetResult(true);476 p.TempUserDataDir?.Dispose();477 }478 public override Task ExitAsync(LauncherBase p, TimeSpan timeout) => Task.CompletedTask;479 public override Task KillAsync(LauncherBase p) => Task.CompletedTask;480 public override Task WaitForExitAsync(LauncherBase p) => Task.CompletedTask;481 }482 private class DisposedState : State483 {484 public void EnterFrom(LauncherBase p, State fromState)485 {486 if (!TryEnter(p, fromState))487 {488 // Delegate Dispose to current state, because it has already changed since489 // transition to this state was initiated.490 p._currentState.Dispose(p);491 }492 else if (fromState != Exited)493 {494 Kill(p);495 p._exitCompletionSource.TrySetException(new ObjectDisposedException(p.ToString()));496 p.TempUserDataDir?.Dispose();497 }498 }499 public override Task StartAsync(LauncherBase p) => throw new ObjectDisposedException(p.ToString());500 public override Task ExitAsync(LauncherBase p, TimeSpan timeout) => throw new ObjectDisposedException(p.ToString());501 public override Task KillAsync(LauncherBase p) => throw new ObjectDisposedException(p.ToString());502 public override void Dispose(LauncherBase p)503 {504 // Nothing to do505 }506 }507 #endregion508 }509 #endregion510 }511}...

Full Screen

Full Screen

ChromiumStartingState.cs

Source:ChromiumStartingState.cs Github

copy

Full Screen

...10 {11 public ChromiumStartingState(StateManager stateManager) : base(stateManager)12 {13 }14 public override Task EnterFromAsync(LauncherBase p, State fromState, TimeSpan timeout)15 {16 if (!StateManager.TryEnter(p, fromState, this))17 {18 // Delegate StartAsync to current state, because it has already changed since19 // transition to this state was initiated.20 return StateManager.CurrentState.StartAsync(p);21 }22 return StartCoreAsync(p);23 }24 public override Task StartAsync(LauncherBase p) => p.StartCompletionSource.Task;25 public override Task ExitAsync(LauncherBase p, TimeSpan timeout) => StateManager.Exiting.EnterFromAsync(p, this, timeout);26 public override Task KillAsync(LauncherBase p) => StateManager.Killing.EnterFromAsync(p, this);27 public override void Dispose(LauncherBase p)28 {29 p.StartCompletionSource.TrySetException(new ObjectDisposedException(p.ToString()));30 base.Dispose(p);31 }32 protected virtual async Task StartCoreAsync(LauncherBase p)33 {34 var output = new StringBuilder();35 void OnProcessDataReceivedWhileStarting(object sender, DataReceivedEventArgs e)36 {37 if (e.Data != null)38 {39 output.AppendLine(e.Data);40 var match = Regex.Match(e.Data, "^DevTools listening on (ws:\\/\\/.*)");41 if (match.Success)42 {43 p.StartCompletionSource.TrySetResult(match.Groups[1].Value);44 }45 }46 }...

Full Screen

Full Screen

KillingState.cs

Source:KillingState.cs Github

copy

Full Screen

...6 {7 public KillingState(StateManager stateManager) : base(stateManager)8 {9 }10 public override async Task EnterFromAsync(LauncherBase p, State fromState, TimeSpan timeout)11 {12 if (!StateManager.TryEnter(p, fromState, this))13 {14 // Delegate KillAsync to current state, because it has already changed since15 // transition to this state was initiated.16 await StateManager.CurrentState.KillAsync(p).ConfigureAwait(false);17 }18 try19 {20 if (!p.Process.HasExited)21 {22 p.Process.Kill();23 }24 }25 catch (InvalidOperationException)26 {27 // Ignore28 return;29 }30 await WaitForExitAsync(p).ConfigureAwait(false);31 }32 public override Task ExitAsync(LauncherBase p, TimeSpan timeout) => WaitForExitAsync(p);33 public override Task KillAsync(LauncherBase p) => WaitForExitAsync(p);34 }35}...

Full Screen

Full Screen

ExitedState.cs

Source:ExitedState.cs Github

copy

Full Screen

...6 {7 public ExitedState(StateManager stateManager) : base(stateManager)8 {9 }10 public void EnterFrom(LauncherBase p, State fromState)11 {12 while (!StateManager.TryEnter(p, fromState, this))13 {14 // Current state has changed since transition to this state was requested.15 // Therefore retry transition to this state from the current state. This ensures16 // that Leave() operation of current state is properly called.17 fromState = StateManager.CurrentState;18 if (fromState == this)19 {20 return;21 }22 }23 p.ExitCompletionSource.TrySetResult(true);24 p.TempUserDataDir?.Dispose();25 }26 public override Task ExitAsync(LauncherBase p, TimeSpan timeout) => Task.CompletedTask;27 public override Task KillAsync(LauncherBase p) => Task.CompletedTask;28 public override Task WaitForExitAsync(LauncherBase p) => Task.CompletedTask;29 }30}...

Full Screen

Full Screen

ExitingState.cs

Source:ExitingState.cs Github

copy

Full Screen

...8 {9 public ExitingState(StateManager stateManager) : base(stateManager)10 {11 }12 public override Task EnterFromAsync(LauncherBase p, State fromState, TimeSpan timeout)13 => !StateManager.TryEnter(p, fromState, this) ? StateManager.CurrentState.ExitAsync(p, timeout) : ExitAsync(p, timeout);14 public override async Task ExitAsync(LauncherBase p, TimeSpan timeout)15 {16 var waitForExitTask = WaitForExitAsync(p);17 await waitForExitTask.WithTimeout(18 async () =>19 {20 await StateManager.Killing.EnterFromAsync(p, this, timeout).ConfigureAwait(false);21 await waitForExitTask.ConfigureAwait(false);22 },23 timeout,24 CancellationToken.None).ConfigureAwait(false);25 }26 public override Task KillAsync(LauncherBase p) => StateManager.Killing.EnterFromAsync(p, this);27 }28}...

Full Screen

Full Screen

DisposedState.cs

Source:DisposedState.cs Github

copy

Full Screen

...6 {7 public DisposedState(StateManager stateManager) : base(stateManager)8 {9 }10 public override Task EnterFromAsync(LauncherBase p, State fromState, TimeSpan timeSpan)11 {12 if (fromState == StateManager.Exited)13 {14 return null;15 }16 Kill(p);17 p.ExitCompletionSource.TrySetException(new ObjectDisposedException(p.ToString()));18 p.TempUserDataDir?.Dispose();19 return null;20 }21 public override Task StartAsync(LauncherBase p) => throw new ObjectDisposedException(p.ToString());22 public override Task ExitAsync(LauncherBase p, TimeSpan timeout) => throw new ObjectDisposedException(p.ToString());23 public override Task KillAsync(LauncherBase p) => throw new ObjectDisposedException(p.ToString());24 public override void Dispose(LauncherBase p)25 {26 // Nothing to do27 }28 }29}...

Full Screen

Full Screen

InitialState.cs

Source:InitialState.cs Github

copy

Full Screen

...6 {7 public InitialState(StateManager stateManager) : base(stateManager)8 {9 }10 public override Task StartAsync(LauncherBase p) => StateManager.Starting.EnterFromAsync(p, this, TimeSpan.Zero);11 public override Task ExitAsync(LauncherBase p, TimeSpan timeout)12 {13 StateManager.Exited.EnterFromAsync(p, this);14 return Task.CompletedTask;15 }16 public override Task KillAsync(LauncherBase p)17 {18 StateManager.Exited.EnterFromAsync(p, this);19 return Task.CompletedTask;20 }21 public override Task WaitForExitAsync(LauncherBase p) => Task.FromException(InvalidOperation("wait for exit"));22 private Exception InvalidOperation(string v)23 {24 throw new NotImplementedException();25 }26 }27}...

Full Screen

Full Screen

StartedState.cs

Source:StartedState.cs Github

copy

Full Screen

...6 {7 public StartedState(StateManager stateManager) : base(stateManager)8 {9 }10 public override Task EnterFromAsync(LauncherBase p, State fromState, TimeSpan timeout)11 {12 StateManager.TryEnter(p, fromState, this);13 return Task.CompletedTask;14 }15 public override Task StartAsync(LauncherBase p) => Task.CompletedTask;16 public override Task ExitAsync(LauncherBase p, TimeSpan timeout) => new ExitingState(StateManager).EnterFromAsync(p, this, timeout);17 public override Task KillAsync(LauncherBase p) => new KillingState(StateManager).EnterFromAsync(p, this);18 }19}...

Full Screen

Full Screen

LauncherBase

Using AI Code Generation

copy

Full Screen

1var browser = await Puppeteer.LaunchAsync(new LaunchOptions2{3 ExecutablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"4});5var page = await browser.NewPageAsync();6await page.ScreenshotAsync("google.png");7await browser.CloseAsync();8PuppeteerSharp is a .NET port of the headless Chrome Node.js API. It provides a high-level API to control Chrome or Chromium over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium. PuppeteerSharp is a .NET port of the headless Chrome Node.js API. It provides a high-level API to control Chrome or Chromium over the DevTools Protocol. It can also be configured to use full (non-headless) Chrome or Chromium. PuppeteerSharp is a .NET port of the headless Chrome Node.js API. It provides a

Full Screen

Full Screen

LauncherBase

Using AI Code Generation

copy

Full Screen

1{2 {3 public static async Task<Browser> LaunchAsync(LaunchOptions options = null)4 {5 if (options == null)6 {7 options = new LaunchOptions();8 }9 var browserFetcher = new BrowserFetcher(options);10 var revisionInfo = await browserFetcher.DownloadAsync().ConfigureAwait(false);11 var executablePath = revisionInfo.ExecutablePath;12 var process = await StartProcessAsync(executablePath, options).ConfigureAwait(false);13 var connection = await Connection.CreateAsync(process, options).ConfigureAwait(false);14 var browser = new Browser(process, connection, options.IgnoreHTTPSErrors, options.DefaultViewport);15 if (options.IgnoreDefaultArgs)16 {17 await browser.SendAsync("Target.setDiscoverTargets", new { discover = true }).ConfigureAwait(false);18 }19 {20 await browser.SendAsync("Target.setDiscoverTargets", new { discover = false }).ConfigureAwait(false);21 }22 return browser;23 }24 internal static async Task<Process> StartProcessAsync(string executablePath, LaunchOptions options)25 {26 var args = new List<string>(options.Args);27 if (options.IgnoreDefaultArgs)28 {29 args.Clear();30 }31 {32 if (!args.Contains("--disable-background-networking"))33 {34 args.Add("--disable-background-networking");35 }36 if (!args.Contains("--enable-features=NetworkService,NetworkServiceInProcess"))37 {38 args.Add("--enable-features=NetworkService,NetworkServiceInProcess");39 }40 if (!args.Contains("--disable-background-timer-throttling"))41 {42 args.Add("--disable-background-timer-throttling");43 }44 if (!args.Contains("--disable-backgrounding-occluded-windows"))45 {46 args.Add("--disable-backgrounding-occluded-windows");47 }48 if (!args.Contains("--disable-breakpad"))49 {50 args.Add("--disable-breakpad");51 }52 if (!args.Contains("--disable-client-side-phishing-detection"))53 {54 args.Add("--disable-client-side-phishing-detection");55 }56 if (!args.Contains("--disable-component-extensions-with-background-pages"))57 {58 args.Add("--disable-component-extensions-with-background-pages");59 }60 if (!args.Contains("--disable-default-apps"))61 {62 args.Add("--disable-default-apps");63 }64 if (!args.Contains("--disable-dev-shm-usage"))

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.

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful