Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

338
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda