private static async Task <RevisionInfo> DownloadChromiumAsync(BrowserFetcherOptions options) { var fetcher = Puppeteer.CreateBrowserFetcher(options); if (fetcher.LocalRevisions().Contains(BrowserFetcher.DefaultRevision)) { return(fetcher.RevisionInfo(BrowserFetcher.DefaultRevision)); } try { Logger?.Debug($"Downloading Chromium r{BrowserFetcher.DefaultRevision}..."); var revisionInfo = await fetcher.DownloadAsync(BrowserFetcher.DefaultRevision); Logger?.Debug($"Chromium downloaded to {revisionInfo.FolderPath}"); return(revisionInfo); } catch (Exception ex) { Logger?.Error($"ERROR: Failed to download Chromium r{BrowserFetcher.DefaultRevision}!)"); Logger?.Error(ex.Message); } return(null); }
private static async Task <FileInfo> DownloadAsync(DirectoryInfo directory, int revision) { await _semaphoreSlim.WaitAsync(); if (!directory.Exists) { directory.Create(); } var fetchOpt = new BrowserFetcherOptions() { Host = Environment.GetEnvironmentVariable("PUPPETEER_CHROMIUM_DOWNLOADHOST"), Path = directory.FullName }; var fetcher = new BrowserFetcher(fetchOpt); if (revision < 1) { string revisionStr = Environment.GetEnvironmentVariable("PUPPETEER_CHROMIUM_REVISION"); if (!int.TryParse(revisionStr, out revision) || revision < 1) { revision = BrowserFetcher.DefaultRevision; } } var info = await fetcher.DownloadAsync(revision).ConfigureAwait(false); _semaphoreSlim.Release(); if (!string.IsNullOrWhiteSpace(info.ExecutablePath)) { return(new FileInfo(info.ExecutablePath)); } TryGetChromeExePath(directory, out var exeFile); return(exeFile); }
/// <inheritdoc cref="IBrowserType.CreateBrowserFetcher(BrowserFetcherOptions)"/> public override IBrowserFetcher CreateBrowserFetcher(BrowserFetcherOptions options = null) { var downloadUrls = new Dictionary <Platform, string> { [Platform.Linux] = "{0}/builds/webkit/{1}/minibrowser-gtk-wpe.zip", [Platform.MacOS] = "{0}/builds/webkit/{1}/minibrowser-mac-{2}.zip", [Platform.Win64] = "{0}/builds/webkit/{1}/minibrowser-win64.zip", }; string path = options?.Path ?? Path.Combine(Directory.GetCurrentDirectory(), ".local-webkit"); string host = options?.Host ?? "https://playwright.azureedge.net"; var platform = options?.Platform ?? GetPlatform(); BrowserFetcherConfig ParamsGetter(Platform platformParam, string revision) { string archiveName = string.Empty; string executablePath = string.Empty; return(new BrowserFetcherConfig { DownloadURL = platformParam == Platform.MacOS ? string.Format(downloadUrls[platformParam], host, revision, GetMacVersion()) : string.Format(downloadUrls[platformParam], host, revision), ExecutablePath = platformParam == Platform.Win32 || platformParam == Platform.Win64 ? "MiniBrowser.exe" : "pw_run.sh", }); } return(new BrowserFetcher(path, platform, PreferredRevision.ToString(CultureInfo.InvariantCulture.NumberFormat), ParamsGetter)); }
static PicGen() { var downloadsFolder = Path.GetTempPath(); var option = new BrowserFetcherOptions { Path = downloadsFolder }; var fetcher = new BrowserFetcher(option); fetcher.DownloadAsync(BrowserFetcher.DefaultRevision).Wait(); var browser = Puppeteer.LaunchAsync(new LaunchOptions { ExecutablePath = fetcher.RevisionInfo(BrowserFetcher.DefaultRevision).ExecutablePath, Headless = true, Args = new[] { !isProd ? "--proxy-server=winip:1080" : "" } }).Result; page = browser.NewPageAsync().Result; page.SetViewportAsync(new ViewPortOptions { Height = 800, Width = 1300 }).Wait(); }
public async void accessSite() { BrowserFetcherOptions bo = new BrowserFetcherOptions(); var browserFetcher = Puppeteer.CreateBrowserFetcher(bo); var revisionInfo = browserFetcher.RevisionInfo(BrowserFetcher.DefaultRevision); if (browserFetcher.LocalRevisions().Count() == 0) { revisionInfo = await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision); } var browser = await Puppeteer.LaunchAsync(new LaunchOptions { ExecutablePath = revisionInfo.ExecutablePath, Headless = false }); var page = await browser.NewPageAsync();//gnb_login_button0 await page.GoToAsync("https://www.jejuair.net/jejuair/kr/main.do"); await page.WaitForSelectorAsync("button.gnb_login_button0"); await page.ClickAsync("button.gnb_login_button0"); }
/// <summary> /// Load the browser fetcher from file /// </summary> /// <returns></returns> protected virtual BrowserFetcher GetBrowserFetcher() { if (BrowserFetcher != null) { return(BrowserFetcher); } var downloadPath = _settingRepository.GetSettingValue <string>("SmartScrapper.Chromium.DownloadPath"); _loggingService.Log(LogEventLevel.Information, $"Attempting to set up puppeteer to use Chromium found under directory {downloadPath}"); if (!Directory.Exists(downloadPath)) { _loggingService.Log(LogEventLevel.Information, "Custom directory not found. Creating directory"); Directory.CreateDirectory(downloadPath); } _loggingService.Log(LogEventLevel.Information, "Downloading Chromium"); var browserFetcherOptions = new BrowserFetcherOptions { Path = downloadPath }; BrowserFetcher = new BrowserFetcher(browserFetcherOptions); return(BrowserFetcher); }
public async Task <Browser> BuildBrowser() { var downloadPath = Path.Combine(Path.GetTempPath(), "puppeteer"); var browserFetcherOptions = new BrowserFetcherOptions { Path = downloadPath }; var browserFetcher = new BrowserFetcher(browserFetcherOptions); await browserFetcher.DownloadAsync(BrowserFetcher.DefaultChromiumRevision); var executableDirectory = Directory.EnumerateDirectories( Directory.EnumerateDirectories(downloadPath) .First()) .First(); var executableFilename = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "chrome.exe" : "chrome"; var executablePath = Path.Combine(executableDirectory, executableFilename); var options = new LaunchOptions { Headless = true, ExecutablePath = executablePath }; var browser = await Puppeteer.LaunchAsync(options); return(browser); }
public static async Task Main(string[] args) { Console.WriteLine("This example downloads the default version of Chromium to a custom location"); var currentDirectory = Directory.GetCurrentDirectory(); var downloadPath = Path.Combine(currentDirectory, "..", "..", "CustomChromium"); Console.WriteLine($"Attemping to set up puppeteer to use Chromium found under directory {downloadPath} "); if (!Directory.Exists(downloadPath)) { Console.WriteLine("Custom directory not found. Creating directory"); Directory.CreateDirectory(downloadPath); } Console.WriteLine("Downloading Chromium"); var browserFetcherOptions = new BrowserFetcherOptions { Path = downloadPath }; var browserFetcher = new BrowserFetcher(browserFetcherOptions); await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision); var executablePath = browserFetcher.GetExecutablePath(BrowserFetcher.DefaultRevision); if (string.IsNullOrEmpty(executablePath)) { Console.WriteLine("Custom Chromium location is empty. Unable to start Chromium. Exiting.\n Press any key to continue"); Console.ReadLine(); return; } Console.WriteLine($"Attemping to start Chromium using executable path: {executablePath}"); var options = new LaunchOptions { Headless = true, ExecutablePath = executablePath }; using (var browser = await Puppeteer.LaunchAsync(options)) using (var page = await browser.NewPageAsync()) { await page.GoToAsync("http://www.google.com"); var jsSelectAllAnchors = @"Array.from(document.querySelectorAll('a')).map(a => a.href);"; var urls = await page.EvaluateExpressionAsync <string[]>(jsSelectAllAnchors); foreach (string url in urls) { Console.WriteLine($"Url: {url}"); } Console.WriteLine("Press any key to continue..."); Console.ReadLine(); } return; }
private async Task <string> DownloadChrome(string path) { BrowserFetcherOptions options = new BrowserFetcherOptions() { Path = path, }; BrowserFetcher fetcher = new BrowserFetcher(options); RevisionInfo info = await fetcher.DownloadAsync(BrowserFetcher.DefaultRevision); return(info.ExecutablePath); }
/// <inheritdoc cref="IBrowserType"/> public override IBrowserFetcher CreateBrowserFetcher(BrowserFetcherOptions options = null) { var downloadUrls = new Dictionary <Platform, string> { [Platform.Linux] = "{0}/chromium-browser-snapshots/Linux_x64/{1}/{2}.zip", [Platform.MacOS] = "{0}/chromium-browser-snapshots/Mac/{1}/{2}.zip", [Platform.Win32] = "{0}/chromium-browser-snapshots/Win/{1}/{2}.zip", [Platform.Win64] = "{0}/chromium-browser-snapshots/Win_x64/{1}/{2}.zip", }; string path = options?.Path ?? Path.Combine(Directory.GetCurrentDirectory(), ".local-chromium"); string host = options?.Host ?? "https://storage.googleapis.com"; var platform = options?.Platform ?? GetPlatform(); BrowserFetcherConfig ParamsGetter(Platform platformParam, string revision) { string archiveName = string.Empty; string executablePath = string.Empty; switch (platformParam) { case Platform.Linux: archiveName = "chrome-linux"; executablePath = Path.Combine(archiveName, "chrome"); break; case Platform.MacOS: archiveName = "chrome-mac"; executablePath = Path.Combine(archiveName, "Chromium.app", "Contents", "MacOS", "Chromium"); break; case Platform.Win32: case Platform.Win64: { // Windows archive name changed at r591479. archiveName = int.TryParse(revision, out int revisionNumber) && revisionNumber > 591479 ? "chrome-win" : "chrome-win32"; executablePath = Path.Combine(archiveName, "chrome.exe"); break; } } return(new BrowserFetcherConfig { DownloadURL = string.Format(CultureInfo.InvariantCulture, downloadUrls[platformParam], host, revision, archiveName), ExecutablePath = executablePath, }); } return(new BrowserFetcher(path, platform, PreferredRevision.ToString(CultureInfo.InvariantCulture.NumberFormat), ParamsGetter)); }
private async Task <Browser> CreateWebBrowser(string ChromePath) { async Task <WebSocket> CreateWebSocketTask(Uri url, IConnectionOptions options, CancellationToken cancellationToken) { var result = new System.Net.WebSockets.Managed.ClientWebSocket(); result.Options.KeepAliveInterval = TimeSpan.Zero; await result.ConnectAsync(url, cancellationToken).ConfigureAwait(false); return(result); } var downloadChrome = string.IsNullOrEmpty(ChromePath) || !File.Exists(ChromePath); if (downloadChrome) { Debug.Write("downloading Chrome..."); var browserFetcherOptions = new BrowserFetcherOptions { Path = $"{AppDomain.CurrentDomain.BaseDirectory}", Platform = Platform.Win64, Product = Product.Chrome }; var browserFetcher = new BrowserFetcher(browserFetcherOptions); var revisionInfo = await browserFetcher.DownloadAsync(); ChromePath = revisionInfo.ExecutablePath; // set the created chrome path Debug.WriteLine("done!"); } var launchOptions = new LaunchOptions { Headless = false, Timeout = (10 * 1000), // 10 sec ExecutablePath = ChromePath, /// $"{AppDomain.CurrentDomain.BaseDirectory}Win64-884014\\chrome-win\\chrome.exe", DefaultViewport = null, // max resolution IgnoreHTTPSErrors = true, Args = new[] { "--no-sandbox", "--disable-gpu" } // "--window-size=800,1080" }; if (Environment.OSVersion.Version.Major < 10) { launchOptions.WebSocketFactory = CreateWebSocketTask; // support for windows-7 } var browser = await Puppeteer.LaunchAsync(launchOptions); return(browser); }
private async Task InitBrowser() { var currentDirectory = Directory.GetCurrentDirectory(); var downloadPath = Path.Combine(currentDirectory, "ChromeRuntime"); if (!Directory.Exists(downloadPath)) { Directory.CreateDirectory(downloadPath); } var browserFetcherOptions = new BrowserFetcherOptions { Path = downloadPath }; var browserFetcher = new BrowserFetcher(browserFetcherOptions); await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision); var executablePath = browserFetcher.GetExecutablePath(BrowserFetcher.DefaultRevision); if (string.IsNullOrEmpty(executablePath)) { throw new Exception("Failed to initialize browser."); } List <string> args = new List <string> { "--no-sandbox", "--disable-setuid-sandbox", "--disable-infobars", "--window-position=0,0", "--ignore-certifcate-errors", "--ignore-certifcate-errors-spki-list", "--user-agent=\"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36\"" }; if (!m_Proxy.Equals("NONE")) { args.Add(string.Format("--proxy-server={0}", m_Proxy)); } var options = new LaunchOptions { Headless = true, IgnoreHTTPSErrors = true, ExecutablePath = executablePath, Args = args.ToArray() }; m_Browser = await Puppeteer.LaunchAsync(options); }
public override void Configure(IFunctionsHostBuilder builder) { var bfOptions = new BrowserFetcherOptions(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { bfOptions.Path = Path.GetTempPath(); } var bf = new BrowserFetcher(bfOptions); var a = bf.DownloadAsync(BrowserFetcher.DefaultChromiumRevision).Result; bf.DownloadAsync(BrowserFetcher.DefaultChromiumRevision).Wait(); var info = new AppInfo { BrowserExecutablePath = bf.GetExecutablePath(BrowserFetcher.DefaultChromiumRevision) }; builder.Services.AddSingleton(info); }
/// <summary> /// Constructor. /// </summary> /// <param name="headless">Set to false to show chromium window.</param> /// <param name="agent">Agent to use when accessing pages. Uses DefaultAgent if non is set.</param> public WebScraper(bool headless = true, string agent = "") { if (agent == "") { agent = DefaultAgent; } var ops = new BrowserFetcherOptions { Path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\scraperion\\browser" }; (new BrowserFetcher(ops).DownloadAsync(BrowserFetcher.DefaultRevision)).Wait(); var browser = Puppeteer.LaunchAsync(new LaunchOptions { Headless = headless, IgnoreHTTPSErrors = true, }); browser.Wait(); m_browser = browser.Result; var page = m_browser.NewPageAsync(); page.Wait(); m_page = page.Result; m_page.Error += (s, e) => { Console.WriteLine("Error:" + e.ToString()); }; m_page.PageError += (s, e) => { Console.WriteLine("Error:" + e.ToString()); }; m_page.Console += (s, e) => { Console.WriteLine(e.Message.Text); }; m_page.SetUserAgentAsync(agent).Wait(); }
/// <inheritdoc cref="IBrowserType.CreateBrowserFetcher(BrowserFetcherOptions)"/> public override IBrowserFetcher CreateBrowserFetcher(BrowserFetcherOptions options = null) { var downloadUrls = new Dictionary <Platform, string> { [Platform.Linux] = "{0}/builds/firefox/{1}/firefox-linux.zip", [Platform.MacOS] = "{0}/builds/firefox/{1}/firefox-mac.zip", [Platform.Win32] = "{0}/builds/firefox/{1}/firefox-win32.zip", [Platform.Win64] = "{0}/builds/firefox/{1}/firefox-win64.zip", }; string path = options?.Path ?? Path.Combine(Directory.GetCurrentDirectory(), ".local-firefox"); string host = options?.Host ?? "https://playwright.azureedge.net"; var platform = options?.Platform ?? GetPlatform(); Func <Platform, string, BrowserFetcherConfig> paramsGetter = (platform, revision) => { string executablePath = string.Empty; switch (platform) { case Platform.Linux: executablePath = Path.Combine("firefox", "firefox"); break; case Platform.MacOS: executablePath = Path.Combine("firefox", "Nightly.app", "Contents", "MacOS", "firefox"); break; case Platform.Win32: case Platform.Win64: executablePath = Path.Combine("firefox", "firefox.exe"); break; } return(new BrowserFetcherConfig { DownloadURL = string.Format(CultureInfo.InvariantCulture, downloadUrls[platform], host, revision), ExecutablePath = executablePath, }); }; return(new BrowserFetcher(path, platform, PreferredRevision.ToString(CultureInfo.InvariantCulture.NumberFormat), paramsGetter)); }
internal async Task DownloadAndInstall() { // Creates the installation folder CreateInstallationFolderIfNotExists(_CHROMIUM_INSTALL_PATH); // Creates the Temp Folder CreateInstallationFolderIfNotExists(CHROMIUM_TEMP_DATA_DIR); // If Chromium isn't installed if (!File.Exists(CHROMIUM_EXECUTION_PATH)) { // Defines the path for installation within the application BrowserFetcherOptions bf = new BrowserFetcherOptions { Path = _CHROMIUM_INSTALL_PATH, Platform = Platform.Win64 }; Console.WriteLine($"Installing Chromium - version {_CHROMIUM_VERSION} at {_CHROMIUM_INSTALL_PATH}."); // Download and install await new BrowserFetcher(bf).DownloadAsync(_CHROMIUM_VERSION); } }
public static IServiceCollection AddPdfGenerator(this IServiceCollection services, IConfiguration configuration) { services.TryAddSingleton(sp => { var logger = sp.GetRequiredService <ILogger <PdfGenerator> >(); var options = new BrowserFetcherOptions() { Product = Product.Chrome, Path = Path.Combine(configuration.GetValue("CHROME_CACHE_PATH", Path.GetTempPath()), "chrome/"), Platform = Platform.Linux }; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { options.Platform = Platform.Win64; } logger.LogInformation("Setting up Puppeteer to use {0} on platform {1} and caching in {2}", options.Product, options.Platform, options.Path); var fetcher = Puppeteer.CreateBrowserFetcher(options); var currentRevisions = fetcher.LocalRevisions(); if (currentRevisions.Any()) { var info = fetcher.GetRevisionInfoAsync().GetAwaiter().GetResult(); logger.LogInformation("Found cached Puppeteer {0} in {0}", info.Revision, info.ExecutablePath); if (info.Downloaded) { return(info); } } logger.LogInformation("Downloading Puppeteer"); return(fetcher.DownloadAsync().GetAwaiter().GetResult()); }); services.TryAddScoped <IPdfGenerator, PdfGenerator>(); return(services); }
public override void Configure(IFunctionsHostBuilder builder) { var bfOptions = new BrowserFetcherOptions(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { bfOptions.Path = Path.GetTempPath(); } var bf = new BrowserFetcher(bfOptions); bf.DownloadAsync(BrowserFetcher.DefaultRevision).Wait(); var info = new AppInfo { BrowserExecutablePath = bf.GetExecutablePath(BrowserFetcher.DefaultRevision) }; var port = GetAvailablePort(); info.RazorPagesServerPort = port; builder.Services.AddSingleton(info); var webHost = Host.CreateDefaultBuilder() .ConfigureWebHostDefaults(webBuilder => { var scriptRoot = Environment.GetEnvironmentVariable("AzureWebJobsScriptRoot"); System.Console.WriteLine($"Starting web server on port {port}"); if (!string.IsNullOrEmpty(scriptRoot)) { webBuilder.UseContentRoot(scriptRoot); } webBuilder.UseUrls($"http://0.0.0.0:{port}") .UseStartup <OfferteTemplater.Startup>(); }) .Build(); webHost.Start(); }
public Printer(IWebHostEnvironment env) { this.env = env; templateFolderPath = Path.Combine(env.ContentRootPath, "Print_Templates"); engine = new RazorLightEngineBuilder() // required to have a default RazorLightProject type, // but not required to create a template from string. .UseFileSystemProject(templateFolderPath) .UseMemoryCachingProvider() .Build(); var bfOptions = new BrowserFetcherOptions(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { bfOptions.Path = Path.GetTempPath(); } var bf = new BrowserFetcher(bfOptions); bf.DownloadAsync(BrowserFetcher.DefaultRevision).Wait(); browserExecutablePath = bf.GetExecutablePath(BrowserFetcher.DefaultRevision); //revisionInfo = (new BrowserFetcher()).DownloadAsync(BrowserFetcher.DefaultRevision).Result; }
public override async void Configure(IFunctionsHostBuilder builder) { builder.Services.AddHttpClient(); //builder.Services.AddSingleton<ILoggerProvider, MyLoggerProvider>(); // for PupeteerSharp browser automation var bfOptions = new BrowserFetcherOptions(); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { bfOptions.Path = Path.GetTempPath(); } var bf = new BrowserFetcher(bfOptions); await bf.DownloadAsync(BrowserFetcher.DefaultChromiumRevision); var info = new AppInfo { BrowserExecutablePath = bf.GetExecutablePath(BrowserFetcher.DefaultChromiumRevision) }; builder.Services.AddSingleton(info); }
private static async Task DownloadAsync(string exePath, int revision) { string path = exePath ?? Environment.GetEnvironmentVariable("PUPPETEER_EXECUTABLE_PATH"); if (!File.Exists(path)) { var fetchOpt = new BrowserFetcherOptions() { Host = Environment.GetEnvironmentVariable("PUPPETEER_CHROMIUM_DOWNLOADHOST"), Path = path }; var fetcher = new BrowserFetcher(fetchOpt); if (revision < 1) { string revisionStr = Environment.GetEnvironmentVariable("PUPPETEER_CHROMIUM_REVISION"); if (!int.TryParse(revisionStr, out revision) || revision < 1) { revision = BrowserFetcher.DefaultRevision; } } await fetcher.DownloadAsync(revision).ConfigureAwait(false); } }
public static async Task <string> Capture(string url, string path) { //return string: path+filename.png var currentDirectory = Directory.GetCurrentDirectory(); var downloadPath = Path.Combine(currentDirectory, "CustomChromium"); Console.WriteLine($"Attemping to set up puppeteer to use Chromium found under directory {downloadPath} "); if (!Directory.Exists(downloadPath)) { Console.WriteLine("Custom directory not found. Creating directory"); Directory.CreateDirectory(downloadPath); } Console.WriteLine("Downloading Chromium..."); var browserFetcherOptions = new BrowserFetcherOptions { Path = downloadPath }; var browserFetcher = new BrowserFetcher(browserFetcherOptions); await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision); var executablePath = browserFetcher.GetExecutablePath(BrowserFetcher.DefaultRevision); if (string.IsNullOrEmpty(executablePath)) { Console.WriteLine("Custom Chromium location is empty. Unable to start Chromium. Exiting.\n Press any key to continue"); Console.ReadLine(); } Console.WriteLine($"Attemping to start Chromium using executable path: {executablePath}"); var options = new LaunchOptions { Headless = true, ExecutablePath = executablePath }; using (var browser = await Puppeteer.LaunchAsync(options)) using (var page = await browser.NewPageAsync()) { await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision); await page.SetViewportAsync(new ViewPortOptions { Width = 1920, Height = 1080 }); var waitUntil = new NavigationOptions { Timeout = 0, WaitUntil = new[] { WaitUntilNavigation.Networkidle0 } }; await page.GoToAsync(url, waitUntil); #region Screenshot Dashboard: var optionsScreenShot = new ScreenshotOptions { FullPage = true }; //Đường dẫn lưu file if (!Directory.Exists(path)) { Console.WriteLine("SavePath directory not found. Creating directory"); Directory.CreateDirectory(path); } string date = DateTime.Now.ToString("yyyyMMddHHmmss"); var outputfile = path + "/capture_" + date + ".png"; await page.ScreenshotAsync(outputfile, optionsScreenShot); #endregion await page.CloseAsync(); //return string = path+filename.png return(outputfile); } }
public void OnPostprocessBuild(BuildReport report) { if (report.summary.platformGroup != BuildTargetGroup.Standalone) { return; } if (!XsollaSettings.InAppBrowserEnabled || !XsollaSettings.PackInAppBrowserInBuild) { return; } var browserPlatform = Platform.Unknown; switch (report.summary.platform) { case BuildTarget.StandaloneOSX: browserPlatform = Platform.MacOS; break; case BuildTarget.StandaloneWindows: browserPlatform = Platform.Win32; break; case BuildTarget.StandaloneWindows64: browserPlatform = Platform.Win64; break; } if (browserPlatform == Platform.Unknown) { Debug.LogWarning($"Build target \"{report.summary.platform}\" is not supported. Packing browser in the build is skipped"); return; } var buildBrowserDirectory = Path.GetDirectoryName(report.summary.outputPath); if (string.IsNullOrEmpty(buildBrowserDirectory)) { throw new Exception(nameof(buildBrowserDirectory)); } buildBrowserDirectory = Path.Combine(buildBrowserDirectory, ".local-chromium"); try { if (Directory.Exists(buildBrowserDirectory)) { Directory.Delete(buildBrowserDirectory, true); } } catch (Exception e) { Debug.LogWarning($"Can't delete existing browser directory. Packing browser in the build is skipped. Exception: {e}"); return; } var projectBrowserDirectory = Path.Combine(Directory.GetCurrentDirectory(), ".local-chromium"); projectBrowserDirectory = Path.Combine(projectBrowserDirectory, $"{browserPlatform}-{BROWSER_REVISION}"); if (Directory.Exists(projectBrowserDirectory)) { buildBrowserDirectory = Path.Combine(buildBrowserDirectory, $"{browserPlatform}-{BROWSER_REVISION}"); foreach (var dirPath in Directory.GetDirectories(projectBrowserDirectory, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(projectBrowserDirectory, buildBrowserDirectory)); } foreach (var filePath in Directory.GetFiles(projectBrowserDirectory, "*.*", SearchOption.AllDirectories)) { File.Copy(filePath, filePath.Replace(projectBrowserDirectory, buildBrowserDirectory), true); } } else { if (Application.internetReachability == NetworkReachability.NotReachable) { Debug.LogWarning("Internet connection is unavailable. Packing browser in the build is skipped"); return; } var fetcherOptions = new BrowserFetcherOptions { Platform = browserPlatform, Path = buildBrowserDirectory }; var browserFetcher = new BrowserFetcher(fetcherOptions); Task.Run(async() => await browserFetcher.DownloadAsync(BROWSER_REVISION)).Wait(); } }