コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 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().");
         }
     }
 }
コード例 #4
0
 public virtual Task OnBrowserAsync(Browser browser, PuppeteerExtraPluginEventOpts opts) => Task.CompletedTask;
コード例 #5
0
 public virtual Task AfterConnectAsync(Browser browser, PuppeteerExtraPluginEventOpts opts) => Task.CompletedTask;