puppeteer-sharp icon indicating copy to clipboard operation
puppeteer-sharp copied to clipboard

Issue with Windows Server 2012 R2

Open ajwadmushtaqv opened this issue 1 year ago • 5 comments

Hello,

I have developed a web scraper using puppeteer-sharp. The scraper runs smoothly when I utilize the latest versions of puppeteer-sharp and chrome.exe and deploy the code on a Windows Server 2022. However, I encounter an error when I attempt to run it on a Windows Server 2012 with an older version of chrome.exe.

Image20230427160436

Despite trying to use an older version of chrome.exe on the Windows Server 2012, the issue persists, and I receive an error indicating that the browser is null.

I appreciate any assistance you can provide and look forward to your advice. Thank you.

Code snippet : PuppeteerSharp.Browser browser = null; try { var location = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Drivers\chrome-win\chrome.exe"); var options = new LaunchOptions { Headless = false, ExecutablePath = location, };

				browser = (Browser)await Puppeteer.LaunchAsync(options);
				var page = await browser.NewPageAsync();

				await page.SetViewportAsync(new ViewPortOptions { Width = 1500, Height = 726 });

ajwadmushtaqv avatar Apr 27 '23 20:04 ajwadmushtaqv

I think that issue is more related to Chrome than Puppeteer-Sharp

kblok avatar Apr 27 '23 20:04 kblok

@kblok , Thank you for getting back. What is the minimum version of chrome.exe compatible with Puppeteer-Sharp please?

ajwadmushtaqv avatar Apr 27 '23 20:04 ajwadmushtaqv

You should be good with 108 or above.

kblok avatar Apr 27 '23 20:04 kblok

Thank you for that I tried the version : 108.0.5305.0 with the code below but i get this error : error

code : public async Task GetHarmonyMobileData() { AppLog.Instance.Write("Scrapping - GetHarmonyMobileData - started"); PuppeteerSharp.Browser browser = null; try { string folderPath = getFolderPath();

			if (!Directory.Exists(folderPath))
			{
				Directory.CreateDirectory(folderPath);
			}

			var location = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Drivers\\chrome-win\\chrome.exe");
			Console.WriteLine(location);
			var options = new LaunchOptions
			{
				Headless = false,
				ExecutablePath = location,

			};

				browser = (Browser)await Puppeteer.LaunchAsync(options);
			
				var page = await browser.NewPageAsync();

				await page.GoToAsync(url);

				await Task.Delay(3000);
				string emailXpathSelector = "/html/body/div[1]/div/main/div/form/input[1]";
				var emailField = await page.XPathAsync(emailXpathSelector);
				await emailField[0].TypeAsync(_username);

				await Task.Delay(10000);
				string nextButtonXpathSelector = "/html/body/div[1]/div/main/div/form/footer/button";
				var nextButton = await page.XPathAsync(nextButtonXpathSelector);
				await nextButton[0].ClickAsync();

				await Task.Delay(10000);
				string passwordXpathSelector = "//*[@id=\"root\"]/div/main/div/form/input[2]";
				var passwordField = await page.XPathAsync(passwordXpathSelector);
				await passwordField[0].TypeAsync(_password);

				await Task.Delay(10000);
				string signInButtonXpathSelector = "/html/body/div[1]/div/main/div/form/footer/button";
				var signInButton = await page.XPathAsync(signInButtonXpathSelector);
				await signInButton[0].ClickAsync();

				await Task.Delay(20000);
				string moreActionsButtonXpathSelector = "//*[@id=\"root\"]/div/div/div/div[2]/main/main/div/div[1]/div[1]/div[1]/div/button[4]";
				var moreActionsButton = await page.XPathAsync(moreActionsButtonXpathSelector);
				await moreActionsButton[0].ClickAsync();

				await Task.Delay(20000);
				string exportButtonXpathSelector = "// html / body / div[2] / div / div / div / ul / li[5]";
				var exportButton = await page.XPathAsync(exportButtonXpathSelector);
				await exportButton[0].ClickAsync();

				await Task.Delay(20000);
				string popUpExportButtonXpathSelector = "/ html / body / div[3] / div / div[2] / div / div[2] / div[3] / div / button";
				var popUpexportButton = await page.XPathAsync(popUpExportButtonXpathSelector);
				await popUpexportButton[0].ClickAsync();

				await Task.Delay(20000);
				string popUpDoneButtonXpathSelector = "/ html / body / div[3] / div / div[2] / div / div[2] / div[3] / div / button";
				var popUpDoneButton = await page.XPathAsync(popUpDoneButtonXpathSelector);
				await popUpDoneButton[0].ClickAsync();

				await Task.Delay(20000);
				AppLog.Instance.Write("Scrapping - GetHarmonyMobileData - Done");
		}
		catch (Exception ex)
		{
			AppLog.Instance.WriteError(ex.ToString());
			Console.WriteLine(ex.ToString());
		}
		finally
		{
			await browser.CloseAsync();
		}

		
	}

With the latest chrome.exe the error is not thrown but that version of chrome.exe is not compatible with windows server 2012. Anything else, you can suggest to try?

ajwadmushtaqv avatar Apr 27 '23 20:04 ajwadmushtaqv

You should be good with 108 or above.

Version M109 is the last version to run on Windows Server 2012(R2). Newer versions won't run.

https://chromereleases.googleblog.com/2023/04/stable-channel-desktop-update.html

amaitland avatar Apr 30 '23 00:04 amaitland