Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

337
Views
Cef Sharp Execute JS

I want to execute JS code, in my cef sharp wpf project.

string jsScript = @"let fakeUserAgent = ""Mozilla / 5.0(Windows NT 10.0; Win32; x64) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 100.0.4896.60 Safari / 537.36""; window.navigator.defineGetter(""userAgent"", function () { return fakeUserAgent; });";

await browser.EvaluateScriptAsPromiseAsync(jsScript);

I need that Js to be executed before page loaded, so i can change userAgent to hide fingerprint. But I caught exception like:

System.Exception: 'Unable to execute javascript at this time, scripts can only be executed within a V8Context. Use the IWebBrowser.CanExecuteJavascriptInMainFrame property to guard against this exception. See https://github.com/cefsharp/CefSharp/wiki/General-Usage#when-can-i-start-executing-javascript for more details on when you can execute javascript. For frames that do not contain Javascript then no V8Context will be created. Executing a script once the frame has loaded it's possible to create a V8Context. You can use browser.GetMainFrame().ExecuteJavaScriptAsync(script) or browser.GetMainFrame().EvaluateScriptAsync to bypass these checks (advanced users only).'

That's cause browser hasn't loaded page yet. But I need to execute it before page is loaded. Does Anybody tried out something like this? ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!