TargetClosedException after Page.CloseAsync()
See original GitHub issueFirst of all, thank you for your tremendous effort that went into this cool project!
I’m trying to generate PDF file, as you will see in the snippet below and although everything works fine, even when I fire multiple concurrent requests that are opening multiple instances of chromium, I’m seeing some exceptions in the log files.
I’ve been able to narrow down that the issue occurs when trying to close the connection. The following exception is being thrown:
PuppeteerSharp.TargetClosedException: 'Navigation failed because browser has disconnected! (Target.detachedFromTarget)'
Example reproducing the issue:
Stream stream;
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);
var browserOptions = new LaunchOptions
{
Headless = true,
Args = new[] { "--no-sandbox" },
};
var browser = await Puppeteer.LaunchAsync(browserOptions, loggerFactory);
var page = await puppeteerService.GetPage(browser);
await page.SetContentAsync("<div>Testing</div>", puppeteerService.GetNavigationOptions());
stream = await page.PdfStreamAsync(puppeteerService.GetPdfOptions());
await page.CloseAsync(); // after this line the exception is thrown
await browser.CloseAsync();
Versions
PuppeteerSharp: 1.12.1 .NET: netcoreapp2.1 Platform: Windows 10
Attached log file (LogLevel.Trace): puppeteer-sharp.log-2019-03-14.txt
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
TargetClosedException after Page.CloseAsync() #1016
The following exception is being thrown: PuppeteerSharp.TargetClosedException: 'Navigation failed because browser has disconnected! (Target.
Read more >Use PuppeteerSharp.TargetClosedException in Puppeteer ...
Want to learn how to use TargetClosedException class in PuppeteerSharp package for your next ... CloseAsync();14 }15 }16}17var browser = await Puppeteer.
Read more >Use PuppeteerSharp.TargetCrashedException. ...
TargetClosedException : Protocol error(IO.read): Target closed. (Page failed to process Inspector.targetCrashed. Exception of type 'PuppeteerSharp.
Read more >Class Browser
CloseAsync(). Closes Chromium and all of its pages (if any were opened). The browser object itself is considered disposed and cannot be used...
Read more >Disposing a Page causes a warning. Is this an issue?
I have the following code that creates, then closes a Chrome page via PuppeteerSharp: var options = new LaunchOptions() {Headless = true, Args...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I created a pull request (https://github.com/kblok/puppeteer-sharp/pull/1218)
I think I found the issue. The problem is when disposing an object, if it has unhandled tasks, it goes to the event. So, what I did was take them and handle them myself in the finalizer.
Let me know what you think.
@Emersonbg I was about to suggest that. One thing is the browser opening a big page and another is the browser receiving a massive CDP message. On the other hand, SetContentAsync is no more than an evaluate setting the HTML content of the
document
. You could implement that and send the content in chunks.