我正在尝试执行以下代码:
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'");
这在本地工作,但在部署到 docker 容器时在最后一行失败。它失败并显示以下消息:
PrintToPdf 在阶段加载页面 1 失败,并显示消息协议错误 (Runtime.callFunctionOn):会话已关闭。很可能页面已关闭。关闭原因:NetworkManager 无法处理 Network.requestWillBeSent。值不能为空。(参数“键”)。在 System.Collections.Concurrent.ConcurrentDictionary 2.ThrowKeyNullException() at System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey key, Func 2.Add(TKey 2 valueFactory) at PuppeteerSharp.Helpers.MultiMap
key, TValue value) 在 PuppeteerSharp.Helpers.AsyncDictionaryHelper`2.GetItemAsync(TKey key) 在 PuppeteerSharp.NetworkManager.OnRequestAsync(RequestWillBeSentPayload e, String interceptionId) 在 PuppeteerSharp.NetworkManager.OnRequestWillBeSentAsync(RequestWillBeSentPayload e) 在 PuppeteerSharp.NetworkManager.Client_MessageReceived(Object sender, MessageEventArgs e)
这个错误是什么意思,我该如何修复/解决它?
如果有任何区别,这将在由 azure 容器实例支持的 azure 函数中运行