I'm trying to fix a race condition - an iframe is blank (even when page inside is fully loaded) and `tabs.captureVisibleTab` will capture fully blank screenshot.
This happens because I load the extension page as inactive pinned tab. And even though the iframe inside will load the page, the iframe itself won't render the content unless the tab is visible "for some time".
I want to replace the "for some time" with a deterministic operation that would guarantee the IFRAME content to draw.
I've tried to call "requestAnimationFrame" (twice in a series), also inject content script that calls it inside the iframe page:
// request animation frame from this tab and all iframes
async function requestAllAnimationFrames() {
await requestAnimationFramePromise();
const tabId = await currentTabIdPromise;
const frames = await browser.webNavigation.getAllFrames({tabId: tabId}).catch(() => [{frameId: 0}]);
const results = await Promise.all(frames.map(frame => browser.scripting.executeScript({
injectImmediately: true,
target: {tabId, frameIds: [frame.frameId]},
// requesting two frames
func: () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))),
})));
iLog('all frames requested animation frame', results);
}
And even though all this code runs after the tab is focused and fully visible, the iframe won't render in time if CPU is slow or page too complex or additional delay is not big enough.
Is there anything else I can execute in the tab or in the iframe page that can be awaited and will cause the content to show?