Skip to content

document.hidden is incorrect if window created but not shown #2826

Closed

Description

@jasisk

Currently, document.hidden is set as false if a new BrowserWindow is created with show: false.
The value is set properly once the window is shown and subsequently hidden again.

Repro

var app = require('app');
var Window = require('browser-window');

app.on('ready', function () {
  var window = new Window({ width: 200, height: 200, show: false });
  var page = window.webContents;

  page.on('did-finish-load', function () {
    page.executeJavaScript(`
      console.log('hidden: ' + document.hidden);
      require('remote').process.exit();
    `);
  });

  window.loadUrl('about:blank');
});
$ electron testcase.js
[76450:0918/002034:INFO:renderer_main.cc(200)] Renderer process started
[76448:0918/002034:INFO:CONSOLE(2)] "hidden: false", source:  (2)

Workaround

var win = require('remote').getCurrentWindow();
Object.defineProperty(document, 'hidden', {
  get() {
    return !(win.isVisible());
  }
});

Activity

  1. zcbenz commented on Sep 21, 2015

    @zcbenz
    Contributor

    Seems that we need to call WebContents::WasHidden to make document.hidden behave correctly.

  2. jasisk commented on Sep 24, 2015

    @jasisk
    Author

    👍 thanks @deepak1556 and @zcbenz!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions