chrome.tabs.captureVisibleTab is capturing elements with display: none; styling

1,204 views
Skip to first unread message

Jonathan Lepolt

unread,
Nov 30, 2015, 3:30:00 PM11/30/15
to Chromium-discuss
I'm having some issues with chrome.tabs.captureVisibleTab where it appears to be capturing a cached version of the current tab. I have a Chrome extension that allows users to capture a screenshot of the current page and send it back to our server. Our extension injects and iframe into the page to allow the user to interact with our app and the current page, and before we do the screenshot capture we hide the iframe...however, there appears to be some race condition where the tab is captured (or perhaps a cached version of it) while the iframe is still visible. I have tried some nasty hacks (like resizing the window to force a repaint/relayout), but nothing has been bulletproof. 

Any help or suggestions are greatly appreciated. Here is some code: 

$iframe.hide();
$iframe
.blur();

chrome
.tabs.captureVisibleTab(null, {format: 'png'}, function (dataUrl) {
 
// Tell the tab we have the screenshot
  sendMessageToCurrentTab
('didTakeScreenshot', {
    dataUrl
: dataUrl
 
});
});


The jQuery is simply setting a CSS property on the element to hide it.

Torne (Richard Coles)

unread,
Nov 30, 2015, 3:39:11 PM11/30/15
to lep...@gmail.com, Chromium-discuss

Possibly it just captures whatever the last drawn frame was, rather than drawing a new one, and your resizing/etc is just changing the timing enough?


--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

Jonathan Lepolt

unread,
Nov 30, 2015, 3:41:46 PM11/30/15
to Chromium-discuss, lep...@gmail.com
Yes, there's certainly something going on there. I have tried various setTimeout hacks, but those are brittle solutions and I'd much rather understand the fix. 

Is there a way to force Chrome to redraw the current frame before taking the screenshot? 

Yuri Wiitala

unread,
Dec 7, 2015, 3:52:41 PM12/7/15
to lep...@gmail.com, Chromium-discuss
Perhaps webkitRequestAnimationFrame would help with some causality guarantees here?  You could do the iframe hide, wait for the "request animation frame" callback to run, and then take the screenshot?

PhistucK

unread,
Dec 7, 2015, 3:59:34 PM12/7/15
to Yuri Wiitala, lep...@gmail.com, Chromium-discuss
Is there any reason why you specifically suggested the deprecated, vendor prefixed and non-standard webkitRequestAnimationFrame instead of the widely supported, standard requestAnimationFrame?


PhistucK

You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.

Yuri Wiitala

unread,
Dec 7, 2015, 7:54:28 PM12/7/15
to PhistucK, Jonathan Lepolt, Chromium-discuss
I was not aware it had been promoted.  I am now, thanks.

Juraj M.

unread,
Apr 30, 2018, 3:31:54 AM4/30/18
to Chromium-discuss, lep...@gmail.com
So did you tried the `window.requestAnimationFrame`?
Because I did and it didn't help. I need to use like 100 ms delay in order to take updated screenshot.
Or have you found another solution?
Reply all
Reply to author
Forward
0 new messages