Open mariahlin opened 7 years ago
I had the same problem and found the solution reading the code. They changed the parameter from requests to interceptRequests but the documentation is not updated. So you need to use:
Offline.options = { interceptRequests : false }
instead of
Offline.options = { requests : false }
For me it's also not working.
I digged a little into the code, and found, that a setTimeout with 0ms is used here:
`setTimeout(function() {
return Offline.getOption("requests") !== !1 ? (Offline.on("confirmed-up", function() {
return waitingOnConfirm ? (waitingOnConfirm = !1, clear()) :void 0;
}), Offline.on("up", flush), Offline.on("down", function() {
return waitingOnConfirm = !1;
}), Offline.onXHR(function(request) {
var _onreadystatechange, _send, async, hold, xhr;
return xhr = request.xhr, async = request.async, xhr.offline !== !1 && (hold = function() {
return holdRequest(request);
}, _send = xhr.send, xhr.send = function(body) {
return request.body = body, _send.apply(xhr, arguments);
}, async) ? null === xhr.onprogress ? (xhr.addEventListener("error", hold, !1),
xhr.addEventListener("timeout", hold, !1)) :(_onreadystatechange = xhr.onreadystatechange,
xhr.onreadystatechange = function() {
return 0 === xhr.readyState ? hold() :4 === xhr.readyState && (0 === xhr.status || xhr.status >= 12e3) && hold(),
"function" == typeof _onreadystatechange ? _onreadystatechange.apply(null, arguments) :void 0;
}) :void 0;
}), Offline.requests = {
flush:flush,
clear:clear
}) :void 0;
}, 0);`
When you put a console.log(Offline.getOption("requests"))
into the timeout closure it returns undefined
Problem described here: http://stackoverflow.com/questions/12959006/javascript-variables-undefined-within-settimeout-function
As I really want request to be false
I added
return void 0;
to the beginning of the closure in setTimeout() and commented out the rest.
Final result:
setTimeout(function() {
return void 0;
},0);
I am using service-worker for handling all data transfers but using the offline.js module for indication of online/offline status
I thought we had tested it previously (about 2 months ago) and requests: false was working correctly at that time, but just few days ago i received a message it was not working, even if I have not updated my project for couple of weeks.