diff --git a/dom/tests/mochitest/chrome/window_focus.xhtml b/dom/tests/mochitest/chrome/window_focus.xhtml index 72759465a51d..bb119ae4a456 100644 --- a/dom/tests/mochitest/chrome/window_focus.xhtml +++ b/dom/tests/mochitest/chrome/window_focus.xhtml @@ -1572,8 +1572,13 @@ function doFrameHistoryTests() resolve({ location: content.location.href, persisted }); }, { once: true }); }); - // make sure that loading a new page and then going back maintains the focus - content.location = "data:text/html,"; + // Make sure that loading a new page and then going back maintains the focus, + // but try to stabilize the page first so that it can enter bfcache. + content.requestAnimationFrame(() => { + content.requestAnimationFrame(() => { + content.location = "data:text/html,"; + }); + }); return goneBack; }); }).then(({ location, persisted }) => {