Shopware and older browsers — here is another chapter: On our Samsung Galaxy Tab 3 10.1 (GT-P5200) tablet using the native Android browser, our online shop displays the message "Invalid form token" on the contact page and on some other pages after attempting to submit a form.
Which is basically no surprise, since the form token is not generated in the first place. We do not consider disabling the CSRF protection, which is supposed to be provided by the token (see also the Magento CE 1.x updates), to be a sensible solution here (of course). After a long search, we came across the file
/themes/Frontend/Responsive/frontend/_public/src/js/jquery.state-manager.js
In this file, no fallbacks are implemented for two methods: For
requestAnimationFrame
and
cancelAnimationFrame
If, for example, the fallback according to https://wiki.selfhtml.org/wiki/JavaScript/Window/requestAnimationFrame#cancelAnimationFrame is implemented here, the relevant lines could:
/**
* requestAnimationFrame proxy
*
* @public
* @method requestAnimationFrame
* @param {Function} callback
* @returns {Number}
*/
requestAnimationFrame: window.requestAnimationFrame.bind(window),
/**
* cancelAnimationFrame proxy
*
* @public
* @method cancelAnimationFrame
* @param {Number} id
*/
cancelAnimationFrame: window.cancelAnimationFrame.bind(window),
look something like this:
requestAnimationFrame : function () {
var lastTime = 0;
if (!window.requestAnimationFrame)
window.requestAnimationFrame = function(callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() { callback(currTime + timeToCall); },
timeToCall);
lastTime = currTime + timeToCall;
return id;
};
},
/**
* cancelAnimationFrame proxy
*
* @public
* @method cancelAnimationFrame
* @param {Number} id
*/
cancelAnimationFrame : function () {
if (!window.cancelAnimationFrame)
window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
},
And, what a surprise: After that, the CSRF protection also works in our online shop implemented with Shopware 5.3.7.
