Open Bug 1532555 Opened 9 months ago Updated 8 months ago

Window.onunload sync ajax request for last tab

Categories

(Core :: DOM: Core & HTML, defect, P3)

60 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: rdeangelis83, Unassigned)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36

Steps to reproduce:

Performing a 'sync' ajax request in Window.onunload function.

Actual results:

I know that an async XHR from unload should not work per spec. That's why we use a sync request. This works in general as expected. But if the 'last' tab of Firefox will be closed (and so the entire Firefox) the sync ajax request will not be fired.

Expected results:

The sync ajax request should be performed by closing the last tab as it will be performed if not the last tab will be closed.

Hi,

Can you please attach a test case so I can try to reproduce this issue?

Flags: needinfo?(rdeangelis83)

Hi David,

so I hope I found a good example to reproduce the bug very simple:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>OnUnloadSyncRequestBug</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
window.onunload = function() {
var result = null;
$.ajax({
cache:false,
async: false,
type: 'GET',
url: 'http://time.jsontest.com/',
success: function(data) {
result = data;
},
error:function(error){
console.log(error);
},
dataType: 'json'
});
console.log(result);
localStorage.setItem('jsontest-time', result.time);
}
</script>
</head>
<body>

</body>
</html>

This simple example performs a sync ajax call again http://time.jsontest.com/ and stores the result in the local storage.
Please open this page 3 times in seperate tabs (and nothing else in FF), each time you will close one of them the time will be update in the local storage by storing the result of the ajax request in the item jsontest-time. This works perfect for the first two tabs. But if you close the last one it doesn't work anymore.

Flags: needinfo?(rdeangelis83)

i couldn't reproduce this issue on Firefox 60 and Nightly 68.0a1 (2019-04-14). it may be the case that I am doing the steps wrong, so I will set a component.

Component: Untriaged → DOM: Events
Product: Firefox → Core
Component: DOM: Events → DOM: Core & HTML

Treating as a defect, since the behavior should be consistent regardless of whether the last tab is being closed.

However, considering that Chrome intends to disable sync XHR in page dismissal in Chrome 75, we might want to do that, too:
https://groups.google.com/a/chromium.org/d/msg/blink-dev/LnqwTCiT9Gs/p-WPDNO9BgAJ

Priority: -- → P3

The chrome team has reverted the change several days ago:
https://chromium.googlesource.com/chromium/src.git/+/54c1ad229a32c01ff824a95abdfd840ed6c57e13

"Reason for revert: Causing a lot of regressions for developer apps."

They now are targeting Chrome 78 to re-remove it, with an opt-out/whitelist for enterprise customers who can't switch quickly. We'll see if that holds.

Okay the estimated release date for chrome 78 is Oct 22nd 2019 and for chrome 79 Dec 10th 2019. So at least for the next 6 Month it will work in Chrome :) So two questions:

  1. Do you plan to fix it FF. Maybe also for FF ESR? The status of the bug is still "UNCONFIRMED".
  2. Was you able to reproduce the bug? I think with the provided example it should be possible.
You need to log in before you can comment on or make changes to this bug.