Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback API needs setters as well as getters #4

Open
aaronmgriffin opened this issue Apr 7, 2015 · 4 comments
Open

Fallback API needs setters as well as getters #4

aaronmgriffin opened this issue Apr 7, 2015 · 4 comments

Comments

@aaronmgriffin
Copy link
Contributor

The defineProp calls for document.hidden and document.visibilityState only contain getters. In older versions of safari this causes the subsequent sets of these properties to error with the message "TypeError: setting a property that has only a getter"

@dcherman
Copy link
Owner

dcherman commented Apr 7, 2015

Do you have a specific version where this breaks for a support comment, and can you make a pull request adding two $.noop settings to each of the descriptors?

@aaronmgriffin
Copy link
Contributor Author

Using browserstack I was able to get it to happen on Safari 5.1 - I didn't test any other versions.

I didn't use noop in my fix, I added actual setters

diff -r e71402529c71 -r 25f8f99f4a29 assets-src/js/jquery.pagevisibility.js
--- a/assets-src/js/jquery.pagevisibility.js        Mon Apr 06 15:45:06 2015 -0500
+++ b/assets-src/js/jquery.pagevisibility.js        Tue Apr 07 10:50:28 2015 -0500
@@ -40,12 +40,18 @@
             defineProp( document, "hidden", {
                 get: function() {
                     return polyfillHidden;
+                },
+                set: function(value) {
+                    polyfillHidden = value;
                 }
             });

             defineProp( document, "visibilityState", {
                 get: function() {
                     return visibilityState;
+                },
+                set: function(value) {
+                    visibilityState = value;
                 }
             });
         }

I don't have the time to submit a PR at the moment, so I'm hoping posting a diff would suffice. If not, let me know, and I can get to it later in the day

@dcherman
Copy link
Owner

dcherman commented Apr 7, 2015

Would certainly be appreciated, but I can get to it later this week if time is a concern.

The setters should definitely be no-op rather than actual setters in order to match what the actual API is; you can't change document.hidden by setting it to true in browsers that have the actual API, so this setting should not be user modifiable in the ideal case.

@aaronmgriffin
Copy link
Contributor Author

Ah, I see this in the comment right below.

// In browsers that support Object.defineProperty,
// setting the two properties on document is essentially a no-op.
// In other older browsers, this is how we'll keep the properties in sync,
// although it's more prone to tampering than with Object.defineProperty.

I'll make the change later on an retest to ensure it's still okay with $.noop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants