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

WinForms - DefaultFocusHandler.OnGotFocus NullReferenceException when JS print from popup #2725

Closed
c2msis opened this issue Apr 16, 2019 · 5 comments

Comments

@c2msis
Copy link

c2msis commented Apr 16, 2019

  • What version of the product are you using?

    • 73.1.120-pre01
  • What architecture x86 or x64?

    • x86
  • On what operating system?

    • Win10
  • Are you using WinForms, WPF or OffScreen?

    • WinForms
  • What steps will reproduce the problem?

    • Open a website with one button with a javascript function, eg.: javascript:CallPrint('name','email');

      Function Code:

function CallPrint(name,email)
{
var printWin=window.open('','','letf=0,top=0,width=600,height=400,toolbar=0,scrollbars=1,status=0');
printWin.document.writeln("<html><body><head></head>");
printWin.document.write("<table align=center ><tr><td align=center></td></tr><tr><td><h3 class=PagTitle>Print this</h3>");
printWin.document.write("<b>Name:</b> "+niss+"<br>");
printWin.document.write("<b>Email:</b> "+nome+"<br>");
printWin.document.write("</td></tr>");
printWin.document.write("<tr><td><table align=center width=400px><tr><td align=center><br><br><br>");
printWin.document.writeln("</td></tr></table></td></tr></table>");
printWin.document.writeln("</body></html>");
printWin.document.close();
printWin.focus();
loadPrint(printWin);}
  • What is the expected output?
    A new window with the preview and the option to print:
    Result

-What do you see instead?

  • It crashes

System.NullReferenceException
HResult=0x80004003
Message=A referência de objecto não foi definida como uma instância de um objecto. Source=CefSharp.WinForms StackTrace:
at CefSharp.WinForms.Internals.DefaultFocusHandler.OnGotFocus(IWebBrowser chromiumWebBrowser, IBrowser browser) at
CefSharp.Internals.ClientAdapter.OnGotFocus(ClientAdapter* , scoped_refptr* browser)

  • Please provide any additional information below.

    • Does the cef log provide any relevant information? (By default there should be a debug.log file in your bin directory)

[0416/145422.219:INFO:CONSOLE(93)] "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.", source: [0416/145428.938:INFO:CONSOLE(403)] "Tue Apr 16 2019 14:54:28 GMT+0100 (Western European Summer Time) Atmosphere: beforeunload event", source: [0416/145430.356:INFO:CONSOLE(403)] "Tue Apr 16 2019 14:54:30 GMT+0100 (Western European Summer Time) Atmosphere: unload event", source: [0416/145430.630:INFO:CONSOLE(93)] "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.", source:

@c2msis c2msis changed the title Crashing DefaultFocusHandler.OnGotFocus Crash - DefaultFocusHandler.OnGotFocus Apr 16, 2019
@c2msis c2msis changed the title Crash - DefaultFocusHandler.OnGotFocus Crash - NullReferenceException DefaultFocusHandler.OnGotFocus Apr 16, 2019
@amaitland
Copy link
Member

Thanks for filling out the bug report. Please fork https://github.com/cefsharp/CefSharp.MinimalExample/tree/cefsharp/73 and provide an example that demos your problem. Thanks

@amaitland amaitland changed the title Crash - NullReferenceException DefaultFocusHandler.OnGotFocus WinForms - DefaultFocusHandler.OnGotFocus NullReferenceException when JS print from popup Apr 16, 2019
@c2msis
Copy link
Author

c2msis commented Apr 17, 2019

Thanks for filling out the bug report. Please fork https://github.com/cefsharp/CefSharp.MinimalExample/tree/cefsharp/73 and provide an example that demos your problem. Thanks

Thanks for the reply,
Here is the example.
I've made a quick page with the JS if you want to test it here

@c2msis
Copy link
Author

c2msis commented Apr 17, 2019

Obs: It doesn't need to print, it's just the JS window popup

@amaitland amaitland added this to the 73.0.0 milestone Apr 17, 2019
amaitland added a commit that referenced this issue Apr 17, 2019
For the print dialog we appear to be passed a CefRefPtr<CefBrowser> reference which doesn't appear to trigger an OnAfterCreated call
so we have no reference to it. Looking at the `CefBrowser`, there's no real data of value, empty url, no frame information (just an invalid frame id)
so for now we'll just ignore it in DefaultFocusHandler, we don't want to handle for popups anyway

Resolves #2725
@amaitland
Copy link
Member

Thanks, fix will be included in the final 73 release.

@c2msis
Copy link
Author

c2msis commented Apr 17, 2019

Thanks, fix will be included in the final 73 release.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants