1

I have a page with a JavaScript based idle sign off script as well as a file upload feature. I noticed that if I opened the dialog then allowed the idle sign off to trigger a redirect to the login page the open file dialog remained open. I would have expected it to be closed when the originating page is unloaded.

Given an input with type of file:

<input type="file" name="file" />

If the user clicks and opens the native file picker dialog window but while it is open the page or frame is redirected via a script the dialog does not close. A script like this should duplicate the behavior:

$('input[type=file]').on('click', function(){
  setTimeout(function(){ 
    window.location.href = "some other page"; 
  }, 2000);
});

You can see the behavior here: https://jsfiddle.net/we40rpfs/1/

I was able to reproduce this in on Windows10 in IE Edge, Chrome 86.0.4240.198 and Firefox 82.0.2.

Interestingly in IE and Chrome the file picker host also crashes sporadically when the user attempts to close or cancel the dialog. Firefox might also crash it as well but I was unable to see it happen.

Is there any way to detect that this dialog is open and programmatically close it before redirecting?

asawyer
  • 17,642
  • 8
  • 59
  • 87
  • How does a script even run when a _modal_ pop-up is open? – Teemu Nov 19 '20 at 18:22
  • @Teemu I assume because the click handler runs first, setting the timeout callback, which then executes from a different context. – asawyer Nov 19 '20 at 19:33
  • Nope, a modal should block a timeout too, as well as promises, ajax calls or anything asynchronous. – Teemu Nov 19 '20 at 20:02
  • 1
    @Teemu Totally makes sense for it to work that way but it's not the behavior I'm seeing or what happens in the jsfiddle. – asawyer Nov 19 '20 at 20:40

1 Answers1

0

It's the expected behavior that the dialog is still open without any user interaction.

At least, you can't programmatically close the dialog with JavaScript. The file dialog is in OS level which can't be reached with JavaScript for security reasons. All interaction with the file dialog must come from the user actually pressing mouse on the system dialog.

Ref link: How to programmatically close select file dialog

Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
  • I totally get that you shouldn't be able to touch native system stuff from javascript, I still find it very strange that the dialog remains open after the browser unloads the page that opened it and that it causes crashes in the browser. – asawyer Nov 18 '20 at 16:24
  • 1
    I can fully understand. I tested in IE 11, Edge Legacy, Edge Chromium and Chrome. I found that the issue can be reproduced in Edge Chromium and Chrome. In IE 11 and Edge Legacy, the page will only be redirected after the dialog is closed. And I didn't find the browsers crash in my tests. So I think it's by design in chromium browsers, you can send a feature request about your concern in the browsers feedback hub. I think we can't do anything more about this behavior except this. – Yu Zhou Nov 19 '20 at 08:39