Skip to content

win.capturePage never calls back after calling hide() for a hidden window #6015

Closed

Description

@brian-mann
  • Electron version: 1.2.2
  • Operating system: Linux

This is a problem only in linux. It works in OSX.

win.hide()
win.capturePage(function(img){
 // never called
})

Activity

  1. added
    blocked/need-info ❌
    on Jun 13, 2016
  2. zcbenz commented on Jun 13, 2016

    @zcbenz
    Contributor

    I can't reproduce by simply capturing a page loaded from filesystem, can you provide a minimal app that can reproduce this problem?

  3. brian-mann commented on Jun 13, 2016

    @brian-mann
    Author

    Okay was able to reproduce in a new example app. There are two things which cause this to happen.

    1. The window must currently be hidden
    2. You must call capturePage asynchronously
    var app = require('electron').app;
    var BrowserWindow = require('electron').BrowserWindow;
    
    var mainWindow = null;
    
    app.on('ready', function() {
      var opts = {
        width: 1280,
        height: 720,
        show: false,
        frame: false,
        devTools: false
      }
    
      mainWindow = new BrowserWindow(opts);
    
      // hiding the window is key, if it is shown it will work
      mainWindow.hide()
    
      mainWindow.loadURL('file://' + __dirname + '/index.html');
    
      setTimeout(function(){
        mainWindow.capturePage(function(data){
            // this function is never called
            console.log("captured data", data)
        })
      }, 1000) // calling this async is key. if you reduce the setTimeout value it will work
    
    });
  4. zcbenz commented on Jun 14, 2016

    @zcbenz
    Contributor

    I can reproduce with your example, calling hide() for a hidden window seems to cause problems.

  5. added and removed
    blocked/need-info ❌
    on Jun 14, 2016
  6. changed the title [-]win.capturePage never calls back in linux when window is hidden[/-] [+]win.capturePage never calls back after calling `hide()` for a hidden window[/+] on Jun 14, 2016
  7. codebytere commented on Sep 27, 2017

    @codebytere
    Member

    closing due to abandonment.

  8. jcj52436999 commented on Sep 27, 2017

    @jcj52436999
  9. astoilkov commented on Jan 11, 2018

    @astoilkov
    Contributor

    Why was this issue closed? I am experiencing the same problem. Should I create a new issue describing the same problem?

  10. codebytere commented on Jan 12, 2018

    @codebytere
    Member

    It was closed since there had been no action on it for over a year, and it is not on our team's immediate radar. Since we try to treat the issues tab as the team's backlog, we try to close issues as needed to bring the project closer to its reality and roadmapping.

  11. astoilkov commented on Jan 12, 2018

    @astoilkov
    Contributor

    Great to hear an explanation @codebytere. Thanks!

    However, this is an existent issue we are experiencing in our app. We have implemented great functionality for increasing the perception loading time of our app by calling capturePage() before quitting the app and then showing the generated image on startup. We are calling hide() before calling capturePage() so users don't notice a lag when closing the app. This approach doesn't work on Windows which is quite unfortunate.

    If this issue is fixed I could write a cool article for how to optimize Electron apps which will increase Electron's authority.

    It would be awesome to reopen the issue. Thanks for considering.

  12. codebytere commented on Jan 12, 2018

    @codebytere
    Member

    i can't promise anything but i'll try to take a look at this issue next week if i have time :) i'll re-open it in the meantime, and let you know if there's progress. Oftentimes closing issues can help us figure out what's actually still an issue too, since we'll get more traction by closing and seeing reactions than by just leaving it and remaining unsure if it's still a problem.

  13. astoilkov commented on Jan 12, 2018

    @astoilkov
    Contributor

    Great. Thanks!

  14. self-assigned this
    on Jan 12, 2018
  15. removed their assignment
    on Feb 10, 2018
  16. sns-sem commented on Feb 23, 2021

    @sns-sem

    This is still an issue on Windows years later: captureWindow is never resolved after calling .hide() on a BrowserWindow.

    Sample to reproduce

    import { app, BrowserWindow } from "electron";
    
    app.on("ready", async () => {
      const browserWindow = new BrowserWindow({
        width: 900,
        height: 600,
        show: true,
        webPreferences: {
          contextIsolation: false,
        },
      });
    
      await browserWindow.loadURL("https://youtube.com");
    
      // This call will resolve as expected
      const image = await browserWindow.capturePage();
      console.log("Screenshot size:", image.getSize());
    
      browserWindow.hide();
    
      // This call does not resolve
      const image2 = await browserWindow.capturePage();
      // This will never be logged as the previous capturePage never resolves
      console.log("Screenshot size", image2.getSize());
    });

    The second capturePage never resolves on Windows 10. If you initiate the BrowserWindow with show: false, capturePage does work. It is explicitly after calling hide. Likewise, if you call .show(), all the previously unresolved calls with resolve and the method will continue working as expected.

    My app's use case requires taking screenshots of the window while it is hidden, and the window switching between shown and hidden.

    • Electron versions: 11.3 (latest), 12.0.0-beta.28, 9.4.3, 10.3.2.
    • OS: Windows 10 (It works on OSX. I have not tested Linux)

    I hope this issue can get looked at.

  17. self-assigned this
    on Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions