hardkoded / puppeteer-sharp

Headless Chrome .NET API
https://www.puppeteersharp.com
MIT License
3.31k stars 439 forks source link

Navigation failed because browser has disconnected! on certain site #1919

Closed FlashPlayer13 closed 2 years ago

FlashPlayer13 commented 2 years ago

Hi,

I have problems with GoToAsync method on certain site after connecting to already running chrome. Here is a code example:

var endpoint = "ws://localhost:9222/devtools/browser/01f2b3b5-6981-4b51-a6fa-554f31fb5370";

var options = new ConnectOptions();
options.BrowserWSEndpoint = endpoint;
options.DefaultViewport = null;
var browser = Puppeteer.ConnectAsync(options).Result;

var page = (browser.PagesAsync().Result).First();
page.GoToAsync("https://www.bet365.com/").Wait();

browser.Disconnect();

Here not on first call, but on 2nd or 3rd I'm encountering this error:

TargetClosedException: Navigation failed because browser has disconnected!

Best way to reproduce error on 2nd call is to run script once then show up browser on foregroud and then run script again. For some reason showing browser from background to foreground causes to this problem.

Next strange thing that with other site (like www.google.com) there are no problems at all with GoToAsync method. So as i said - only my target bet365 site causes this error.

I found similar problem here (but without solution): https://githubhot.com/repo/alixaxel/chrome-aws-lambda/issues/104?page=1

kblok commented 2 years ago

Use await/async patterns. First, Result and Wait are blockers.