Window.onunload sync ajax request for last tab
Categories
(Core :: DOM: Core & HTML, defect, P3)
Tracking
()
People
(Reporter: rdeangelis83, Unassigned)
Details
Attachments
(1 file)
991 bytes,
text/html
|
Details |
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.
Comment 1•9 months ago
|
||
Hi,
Can you please attach a test case so I can try to reproduce this issue?
Reporter | ||
Comment 2•9 months ago
|
||
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.
Reporter | ||
Comment 3•9 months ago
|
||
Comment 4•8 months ago
|
||
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.
Updated•8 months ago
|
Comment 5•8 months ago
|
||
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
Reporter | ||
Comment 6•8 months ago
|
||
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."
Comment 7•8 months ago
|
||
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.
Reporter | ||
Comment 8•8 months ago
|
||
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:
- Do you plan to fix it FF. Maybe also for FF ESR? The status of the bug is still "UNCONFIRMED".
- Was you able to reproduce the bug? I think with the provided example it should be possible.
Description
•