public async Task <Browser> LaunchAsync(LaunchOptions options)
        {
            //options = merge(this._defaultLaunchOptions, options)
            ResolvePluginDependencies();
            OrderPlugins();

            foreach (PuppeteerExtraPlugin plugin in _plugins)
            {
                options = (await plugin.BeforeLaunchAsync(options)) ?? options;
            }

            PuppeteerExtraPluginEventOpts opts = new PuppeteerExtraPluginEventOpts("launch", options, DefaultArgs);

            CheckPluginRequirements(opts);

            Browser browser = await Puppeteer.LaunchAsync(options);

            PatchPageCreationMethods(browser);

            foreach (PuppeteerExtraPlugin plugin in _plugins)
            {
                await plugin.BindBrowserEventsAsync(browser, opts);
            }

            return(browser);
        }
        internal async Task BindBrowserEventsAsync(Browser browser, PuppeteerExtraPluginEventOpts opts)
        {
            browser.TargetCreated += async(sender, args) => await InternalOnTargetCreatedAsync(args.Target);

            browser.TargetChanged += async(sender, args) => await OnTargetChangedAsync(args.Target);

            browser.TargetDestroyed += async(sender, args) => await OnTargetDestroyedAsync(args.Target);

            browser.Disconnected += async(sender, args) => await OnDisconnectedAsync();

            await AfterLaunchAsync(browser, opts);
            await AfterConnectAsync(browser, opts);
            await OnBrowserAsync(browser, opts);
        }
 public void CheckPluginRequirements(PuppeteerExtraPluginEventOpts opts)
 {
     foreach (PuppeteerExtraPlugin plugin in _plugins)
     {
         if (opts.Context == "launch" && ((plugin.Requirements & PluginRequirements.Headful) == PluginRequirements.Headful) && opts.Options.Headless)
         {
             throw new InvalidOperationException($"Plugin '{plugin.Name}' is not supported in headless mode.");
         }
         if (opts.Context == "connect" && ((plugin.Requirements & PluginRequirements.Launch) == PluginRequirements.Launch))
         {
             throw new InvalidOperationException($"Plugin '{plugin.Name}' doesn't support puppeteer.connect().");
         }
     }
 }
 public virtual Task OnBrowserAsync(Browser browser, PuppeteerExtraPluginEventOpts opts) => Task.CompletedTask;
 public virtual Task AfterConnectAsync(Browser browser, PuppeteerExtraPluginEventOpts opts) => Task.CompletedTask;