Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while fulfilling of JS: Request BrowserId : 1 not found it's likely the browser is already closed #4621

Open
1 task done
maksimrudn opened this issue Nov 1, 2023 · 39 comments
Labels
upstream These issues require fixing in the Chromium Embedded Framework(CEF) or Chromium.
Milestone

Comments

@maksimrudn
Copy link

maksimrudn commented Nov 1, 2023

Is there an existing issue for this?

  • I have searched both open/closed issues, no issue already exists.

CefSharp Version

117.2.40

Operating System

Windows 10

Architecture

x64

.Net Version

.net 6.0

Implementation

OffScreen

Reproduction Steps

Version: Above 108

Steps:
Create instance of CefSharp.OffScreen.ChromiumWebBrowser
br = CefSharp.OffScreen.ChromiumWebBrowser();

Go by url 2 times:
br.Load(url)
await br.EvaluateScriptAsPromiseAsync(script);
br.Load(url)
await br.GetSourceAsync();
br.Load(url)

Fulfill JS
_browser.EvaluateScriptAsPromiseAsync(script)

Expected behavior

Fulfilling of JS

Actual behavior

JS Error Request BrowserId : 1 not found it's likely the browser is already closed

Regression?

After regression to version 108 problem dissapeared.

Known Workarounds

Likely problem is here
https://github.com/cefsharp/CefSharp/blob/master/CefSharp.BrowserSubprocess.Core/CefAppUnmanagedWrapper.cpp
Look at history..

Does this problem also occur in the CEF Sample Application

Yes using WPF/OffScreen command line args

Other information

No response

@amaitland

This comment was marked as outdated.

@maksimrudn

This comment was marked as off-topic.

@amaitland

This comment was marked as outdated.

@amaitland

This comment was marked as outdated.

@daveime68

This comment was marked as off-topic.

@ficho-hun
Copy link

ficho-hun commented Jan 9, 2024

It seems that happening with only some Websites.
I enabled the CEF logging, maybe can you find here something.

cef.log

@netmaxik
Copy link

netmaxik commented Feb 1, 2024

good day @amaitland
I did https://github.com/netmaxik/CefSharp.MinimalExample.netcore special.
Use WPF project and press Test button. On title you will see Elements under mouse. Press Test again to stop. After you go to : https://accounts.google.com/?hl=en, wait to load and press test again you see that error appears . For me last version where it was work correctly was : 112.3.0 After that i got that error everywhere.

@nebojsasandin
Copy link

@netmaxik have you tried the new v121.3.x ? Has the issue been resolved @amaitland ?
I'm experiencing the same problem @netmaxik is, basically anything related to Google (google drive, docs, gmail, accounts, etc...) is broken on all versions past 112.3.0. Haven't tested v121.3.x though.

@amaitland

This comment was marked as outdated.

@nebojsasandin

This comment was marked as outdated.

@amaitland

This comment was marked as outdated.

nebojsasandin added a commit to nebojsasandin/CefSharp that referenced this issue Mar 3, 2024
Modified Google test to replicate this issue: cefsharp#4621
@nebojsasandin
Copy link

Not sure if this was what I was supposed to do (I've never done this before), but I forked the entire master branch, changed the offscreen test cs file, included the part which causes an exception, and initialized pull request on this one single file from my fork: #4741

I could not get it to compile or run though, there was a whole bunch of errors in the C++ sources which I'm unfamiliar with, so I could not see if the test truly replicates the issue described here, but I did test it in async fashion as well in the original test I sent you, and it did produce the same exception, so hopefully you'll be able to replicate the issue on your end and see what's causing it in the first place, so we can get this resolved.

Thank you.

nebojsasandin added a commit to nebojsasandin/CefSharp that referenced this issue Mar 9, 2024
@amaitland
Copy link
Member

amaitland commented Mar 24, 2024

initialized pull request on this one single file from my fork: #4741

For the example provided by @nebojsasandin you can forcibly isolate the origins and the script executes correctly.

settings.CefCommandLineArgs.Add("isolate-origins", "https://accounts.google.com,https://chrome.google.com,https://chromewebstore.google.com");

@amaitland
Copy link
Member

Loading chrome://process-internals/#site-isolation in Chrome I see

image

In the CEF Sample Application (cefclient) it looks like

image

So CEF doesn't have the same google urls isolated like Chrome does.

You can add the following command line arg to mimic the Chrome behaviour.

settings.CefCommandLineArgs.Add("isolate-origins", "https://accounts.google.com,https://chrome.google.com,https://chromewebstore.google.com");

@amaitland
Copy link
Member

I've created chromiumembedded/cef#3672 to see if CEF can set the built-in isolations by default.

Until then you can use the workaround I've listed above.

It seems that happening with only some Websites.

@ficho-hun Did you observe the issue on websites other than the google ones?

After you go to : https://accounts.google.com/?hl=en,

@netmaxik If you are still experiencing this issue then please test with the workaround provided in #4621 (comment)

@netmaxik
Copy link

@amaitland I did test with : settings.CefCommandLineArgs.Add("isolate-origins", "https://accounts.google.com,https://chrome.google.com,https://chromewebstore.google.com");.

What I found out is :

  1. If I start application - press Test button - then press Sign In or went to https://accounts.google.com/?hl=en, - I got problem. same error. BUT
  2. If I start application - DO not press Test and press Sign In to google or https://accounts.google.com/?hl=en - then press test - its working normally.

@amaitland
Copy link
Member

@netmaxik If you create a failing Unit test and create a PR then I will have a look. You can use #4741 as a reference for creating a test.

@amaitland amaitland added the upstream These issues require fixing in the Chromium Embedded Framework(CEF) or Chromium. label Mar 25, 2024
@nebojsasandin
Copy link

nebojsasandin commented Mar 26, 2024

@netmaxik Have you tried adding more domains to the list? In my use-case I had to add few extra domains:
https://accounts.google.com,https://chrome.google.com,https://chromewebstore.google.com,https://reportcontent.google.com,https://support.google.com,https://www.google.com
It would be good if we could do: *.google.com to cover all of google's sub-domains, but it appears that "isolate-origins" setting is not that versatile.
@amaitland , it seems that the CEF staff don't recognize this as a bug, or anything that needs to be changed, however, this does break the functionality of the CefSharp. Is there a more permanent or future-proof solution other than knowing which domains are breaking this entire facility? What if there is another domain (other than Google) which also breaks JavaScript in CefSharp, but in order to capture it - one would have to know the domain name.

@netmaxik
Copy link

netmaxik commented Mar 27, 2024

@nebojsasandin I did most off them.. nothing help. I do not know how to create test units... so do not know my next steps. But issue still continue :(.

@amaitland Im sorry I cannot create Test Units. I did not know how to do that. :( And now really do not have time to learn and understand that :( really sorry..

nebojsasandin added a commit to nebojsasandin/CefSharp that referenced this issue Mar 27, 2024
New test to mimic issue cefsharp#4621 where isolate-origins settings does not help.
@nebojsasandin
Copy link

nebojsasandin commented Mar 27, 2024

@netmaxik , when I test your code based on the instructions you provided (click on Test button, then navigate to Sign In, it still works when I include "https://www.google.com" to the isolate-origins).

[EDIT] - turns out you can do this: https://[*.].google.com but still, the error persists when one tries to switch from Google to Gmail.

...However, I realized that there are still issues with this even with the workaround. So maybe that's what you're talking about.
@amaitland , I've created a new pull request: #4771 with the new method created, the one which demonstrates that "isolate-origins" which includes all domains being visited is still producing the same error.

[EDIT] - as a side-note, I did try: disable-web-security; disable-features=IsolateOrigins,site-per-process; disable-site-isolation-trials; and neither of these helped.

@amaitland amaitland added this to the 125.0.x milestone May 6, 2024
@amaitland
Copy link
Member

it seems that the CEF staff don't recognize this as a bug, or anything that needs to be changed, however, this does break the functionality of the CefSharp. Is there a more permanent or future-proof solution other than knowing which domains are breaking this entire facility?

The problem is in the Alloy Bootstrap, not something that can be fixed directly in CefSharp. The interesting news is that CEF is just started to remove the Alloy Boostrap (chromiumembedded/cef#3685) and has added support for using the Chrome Bootstrap with Alloy Style OSR windows.

Starting in M125 you'll be able to use CefSettings.ChromeRuntime = true and the same isolation settings a Chrome will be used.

I've added both tests (they'll only run locally, not on Appveyor) and migrated the CefSharp.Test project to using the ChromeRuntime. Both now pass without any changes or custom origin isolations.

In ~M127 the Alloy Bootstrap will be removed.

I've created a new pull request: #4771 with the new method created, the one which demonstrates that "isolate-origins" which includes all domains being visited is still producing the same error.

@nebojsasandin Thanks for providing the tests 👍 The problem is likely in the alloy bootstrap and should be resolved by switching to the Chrome bootstrap.

@heart-of-hero
Copy link

The above-mentioned issue still persists. Does anyone have a solution?

  • Project type: WinForm, VB .NET Framework 4.8.1

  • Operating System: Win 10, x64

  • CEFSharp version: Stable releases 125 and 126 from NuGet.

  • Other settings and prerequisites:

    • ChromeRuntime=true.
    • The error occurs regardless of whether "custom origin isolations" are enabled or not.
    • The timing for allowing Script execution has been confirmed through methods such as CanExecuteJavascriptInMainFrame.
  • Issue occurrence process:
    The issue occurs only after a page navigation is triggered by either manual or script operations on any webpage.
    ExecuteScriptAsync() always runs normally, but EvaluateScriptAsync() throws the above error.
    On the JavaScript side, CefSharp.BindObjectAsync() fails.

I am unsure whether this is a default behavior change in CEFSharp or a bug.
Looking forward to a solution, thank you.

@stormcleric
Copy link

stormcleric commented Jul 23, 2024

True, I'm randomly getting this error after upgrading to latest version

EDIT: or maybe not so randomly! It happens every 10 minutes, accurately.

I'm checking a URL every 3 seconds - in short, I do:

while (true) {
Browser.Load(url);
// Run several calls to JS
Sleep(3000);
}

Every 10 minutes I get that error when running the JS call. A dirty workaround for me is to redirect to another page by clicking on a button in the same page, so let's say there's a "go to my profile" button, I press that, and after going to my profile, I can Browser.Load(url) and everything keeps working fine for another solid 10 minutes.

@stormcleric
Copy link

The above-mentioned issue still persists. Does anyone have a solution?

  • Project type: WinForm, VB .NET Framework 4.8.1

  • Operating System: Win 10, x64

  • CEFSharp version: Stable releases 125 and 126 from NuGet.

  • Other settings and prerequisites:

    • ChromeRuntime=true.
    • The error occurs regardless of whether "custom origin isolations" are enabled or not.
    • The timing for allowing Script execution has been confirmed through methods such as CanExecuteJavascriptInMainFrame.
  • Issue occurrence process:
    The issue occurs only after a page navigation is triggered by either manual or script operations on any webpage.
    ExecuteScriptAsync() always runs normally, but EvaluateScriptAsync() throws the above error.
    On the JavaScript side, CefSharp.BindObjectAsync() fails.

I am unsure whether this is a default behavior change in CEFSharp or a bug. Looking forward to a solution, thank you.

Well it seems to be fixed if you specifically set ChromeRuntime=false in your settings. At least this worked for me after upgrading, and everything seems to be working alright.

@GrabzIt
Copy link
Contributor

GrabzIt commented Jul 26, 2024

I have also been experiencing the same issue with ChromeRuntime=true on random websites. It's not just related to Google websites.

I found it on: https://www.visualcom.pl/kontakt/wymagania-plikow-produkcyjnych'

@amaitland
Copy link
Member

Well it seems to be fixed if you specifically set ChromeRuntime=false in your settings. At least this worked for me after upgrading, and everything seems to be working alright.

If the problem only occurs when using the Chrome Runtime then an upstream issue will need to be raised.

https://github.com/chromiumembedded/cef/issues

The alloy bootstrap will be removed in M128, you'll only be able to revert back for a short time.

I have also been experiencing the same issue with ChromeRuntime=true on random websites. It's not just related to Google websites.

I found it on: https://www.visualcom.pl/kontakt/wymagania-plikow-produkcyjnych'

@GrabzIt Can you please create a unit test that reproduces the problem you are seeing (and submit a PR).

There are already tests at

public class Issue4621
you can use those as a basis, just add another to the same class


To set expectations, I've not seen anything here that suggests this is an issue that can be fixed directly in CefSharp. If upstream changes are required then this will likely take some time to get fixed as reproducing the issue directly in C++ will be difficult.

I potential workaround would be to switch to using Chrome DevTools Protocol for executing javascript.

https://github.com/cefsharp/CefSharp.Dom?tab=readme-ov-file#dom-access


Hopefully at some point CEF will add equivalent functionality directly (chromiumembedded/cef#3631)

@GrabzIt
Copy link
Contributor

GrabzIt commented Jul 28, 2024

I have found that the errors happen after a long period of time, so hours or days, then carry on happening. So this isn't something that is suitable for a unit test.

I am going to try and use the Chrome DevTools Protocol to see if that fixes the issue.

@stormcleric
Copy link

I have found that the errors happen after a long period of time, so hours or days, then carry on happening. So this isn't something that is suitable for a unit test.

I am going to try and use the Chrome DevTools Protocol to see if that fixes the issue.

Not on my specific case - they were after 10 solid minutes - but it's funny it's time dependant.

@drRobertDev
Copy link

I have found that the errors happen after a long period of time, so hours or days, then carry on happening. So this isn't something that is suitable for a unit test.
I am going to try and use the Chrome DevTools Protocol to see if that fixes the issue.

Not on my specific case - they were after 10 solid minutes - but it's funny it's time dependant.

yes also to me afte 10 minutes, dont know why this timing. (rendering working, on paint work, just JS code dont work)

@nabkawe
Copy link

nabkawe commented Aug 12, 2024

I have found that the errors happen after a long period of time, so hours or days, then carry on happening. So this isn't something that is suitable for a unit test.
I am going to try and use the Chrome DevTools Protocol to see if that fixes the issue.

Not on my specific case - they were after 10 solid minutes - but it's funny it's time dependant.

I feel this is Google's way of breaking Chrome Extensions that need (JS level magic to do stuff like hide ads.)
I have the exact issue after upgrading from 112 to the latest stable nuget.

@nabkawe
Copy link

nabkawe commented Aug 12, 2024

EDIT: While this helped with the severity of the issue, it didn't actually solve it, I still have to naviage away and then back to the page I need

I had this error in another site, I "possibly" managed to fix it by turning off chromeruntime from the CefSharp Settings

` CefSharp.WinForms.CefSettings se = new CefSharp.WinForms.CefSettings();
se.CachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\CEF";
se.EnablePrintPreview();
se.CefCommandLineArgs.Add("enable-media-stream");
se.JavascriptFlags = "--enable-media-stream";
se.JavascriptFlags = "--AllowRunningInsecureContent";
se.CefCommandLineArgs.Add("enable-usermedia-screen-capturing");
se.CefCommandLineArgs.Add("disable-site-isolation-trials"); // didn't work
se.ChromeRuntime = false; // worked instantly.
CefSharp.Cef.Initialize(se);

`

@onlylau
Copy link

onlylau commented Sep 30, 2024

Now they remove this "se.ChromeRuntime = false;" and i cant run my aplication! :\ start getting that error "Message = "Request BrowserId : 1 not found it's likely the browser is already closed""

@nuno84
Copy link

nuno84 commented Oct 3, 2024

Now they remove this "se.ChromeRuntime = false;" and i cant run my aplication! :\ start getting that error "Message = "Request BrowserId : 1 not found it's likely the browser is already closed""

I also have this issue. Did you find any workaround?
I am using CEF v128.4.90, it takes way less than 10 minutes and I amaccessing a common website but google related.

@onlylau
Copy link

onlylau commented Oct 4, 2024 via email

@amaitland
Copy link
Member

Please create a unit test inside the CefSharp.Test project and submit a PR.

There are already tests at

public class Issue4621
you can use those as a basis, just add another to the same class

Until there's a unit test that reproduces the problem there's not really anything actionable here.

@aimcosoftware
Copy link

aimcosoftware commented Nov 7, 2024

This is still an issue in 130.1.90.0 only when using EvaluateScriptAsync. ExecuteScriptAsync doesn't fail.
Only had this issue since Chrome bootstrap, all Alloy versions since 106 have worked.

Steps
Navigate to a page. On FrameLoadEnd, inject some DOM altering script , I'm using:

for(elm of document.body.getElementsByTagName("div")){ elm.style.border = "1px solid red" }
Navigate to other pages, within 4-6 pages, you'll get the error.

CEFSharp is entirely broken with this change, happy to provide any assistance to track it down.

@nuno84
Copy link

nuno84 commented Nov 7, 2024

But from what I understand, ExecuteScriptAsync doesn't return any data, and I need to get data from the browser. If I am right, than I cannot use that alternative.
Thank you for any suggestions.

@aimcosoftware
Copy link

aimcosoftware commented Nov 7, 2024

@nuno84 ExecuteScriptAsync doesn't return any data. I only mentioned it because it works, where EvaluateScriptAsync does not.
The page size seems to make a difference, I'm testing with these pages, they often fail on the 1st or 2nd navigate.

@amaitland
Copy link
Member

The page size seems to make a difference, I'm testing with these pages, they often fail on the 1st or 2nd navigate.

@aimcosoftware Can you turn that into a XUnit test as per #4621 (comment)

I need a reliable way to reproduce the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream These issues require fixing in the Chromium Embedded Framework(CEF) or Chromium.
Projects
None yet
Development

No branches or pull requests