diff --git a/lib/core/public/run-rules.js b/lib/core/public/run-rules.js index a358afaa26..1d7ad954df 100644 --- a/lib/core/public/run-rules.js +++ b/lib/core/public/run-rules.js @@ -28,18 +28,18 @@ function runRules(context, options, resolve, reject) { axe.utils.collectResultsFromFrames(context, options, 'rules', null, res, rej); }); } + let scrollState; q.defer(function (res, rej) { if (options.restoreScroll) { - const scrollState = axe.utils.getScrollState(); - audit.run(context, options, res, rej); - axe.utils.setScrollState(scrollState); - - } else { - audit.run(context, options, res, rej); + scrollState = axe.utils.getScrollState(); } + audit.run(context, options, res, rej); }); q.then(function (data) { try { + if (scrollState) { + axe.utils.setScrollState(scrollState); + } if (options.performanceTimer) { axe.utils.performanceTimer.auditEnd(); }