Is it possible to change the page visibility?

59 views
Skip to first unread message

Seth Bertalotto

unread,
Jul 12, 2017, 7:41:30 PM7/12/17
to jsdom
In older versions of jsdom (< 10), I had tests that could set "document.hidden = true" or rely on "visibilitychange" of the document to test different things (i.e. viewport detection of an element). However, in the latest version of jsdom, this is no longer allowed. I get errors like:

     TypeError: Cannot set property hidden of [object Object] which has only a getter

When trying to set "document.hidden". Is this no longer supported by jsdom or is there another way to change the page visibility?

Thanks,
Seth

Domenic Denicola

unread,
Jul 12, 2017, 7:54:06 PM7/12/17
to js...@googlegroups.com
You can change it the same way you do in browsers, by using Object.defineProperty.



From: Seth Bertalotto <se...@bertalotto.net>
Sent: Jul 12, 2017 19:41
To: jsdom
Subject: Is it possible to change the page visibility?

--
You received this message because you are subscribed to the Google Groups "jsdom" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsdom+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Seth Bertalotto

unread,
Jul 12, 2017, 8:13:59 PM7/12/17
to jsdom
Thanks for the tip, I'm probably doing this wrong but I tried:

            Object.defineProperty(document, 'hidden', {
                value: false
            });

But get the error: "TypeError: Cannot redefine property: hidden". So how would I redefine it if its already defined?

Trying

            Object.defineProperty(document, 'hidden', {
                enumerable: false,
                configurable: true,
                writable: true,
                // value: false,
                set: function(value) {
                    this.hidden = value;
                }
            });

Gets me: "TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #<Object>"

Domenic Denicola

unread,
Jul 13, 2017, 2:11:04 PM7/13/17
to js...@googlegroups.com

Hmm, that should be working (the first version). At least, as long as it works in browsers. One of us can try to debug it at some point… If you could file an issue, following the issue template, at https://github.com/tmpvar/jsdom/issues, about defineProperty not working, then we can try to fix it soon.

Seth Bertalotto

unread,
Jul 14, 2017, 3:50:01 PM7/14/17
to js...@googlegroups.com
Thanks Domenic. I noticed I wasn't on the latest jsdom, I will test on the latest and see if it's still an issue. 

--
Seth
You received this message because you are subscribed to a topic in the Google Groups "jsdom" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jsdom/tzhDcbfuad8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jsdom+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages