I am tryng to execute the following code:
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
#if DEBUG
var chromeLocation = Path.Combine(context.FunctionDirectory, @"../.local-chromium/Win64-706915/chrome-win/chrome.exe");
#endif
stage = "Start Browser";
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
Args = new[] { "--no-sandbox", "--shm-size=1gb" }
#if DEBUG
,
ExecutablePath = chromeLocation,
IgnoreHTTPSErrors = true
#endif
});
var page = await browser.NewPageAsync();
var headers = new Dictionary<string, string> { { "Authorization", $"Bearer {authToken}" } };
await page.SetExtraHttpHeadersAsync(headers);
stage = "Load Page";
await page.GoToAsync(printToPdfRequest.TargetUrl);
stage = "Load Page 1";
Thread.Sleep(5000);
// This waits unti the loader has disappeared or times-out after 30 seconds
await page.WaitForFunctionAsync("() => document.getElementsByClassName('loader').length > 0 && document.getElementsByClassName('loader')[0].style.length > 0 && document.getElementsByClassName('loader')[0].style[0] === 'display' && document.getElementsByClassName('loader')[0].style['display'] === 'none'");
This works locally but fails on the last line when deployed to a docker container. It fails with the following message:
Failed PrintToPdf at stage Load Page 1 with message Protocol error (Runtime.callFunctionOn): Session closed. Most likely the Page has been closed.Close reason: NetworkManager failed to process Network.requestWillBeSent. Value cannot be null. (Parameter 'key'). at System.Collections.Concurrent.ConcurrentDictionary2.ThrowKeyNullException() at System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey key, Func2 valueFactory) at PuppeteerSharp.Helpers.MultiMap
2.Add(TKey key, TValue value) at PuppeteerSharp.Helpers.AsyncDictionaryHelper`2.GetItemAsync(TKey key) at PuppeteerSharp.NetworkManager.OnRequestAsync(RequestWillBeSentPayload e, String interceptionId) at PuppeteerSharp.NetworkManager.OnRequestWillBeSentAsync(RequestWillBeSentPayload e) at PuppeteerSharp.NetworkManager.Client_MessageReceived(Object sender, MessageEventArgs e)
What does this error mean and how can I fix/get around it?
This is running in an azure function backed by an azure container instance if it makes any difference