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

PhantomJS: Script error on Object.defineProperty for DOM element and Event objects #823

Closed
miherlosev opened this issue Sep 28, 2016 · 8 comments
Assignees
Labels
AREA: client REASON: won't fix STATE: Auto-locked Issues that were automatically locked by the Lock bot TYPE: bug

Comments

@miherlosev
Copy link
Contributor

We setup events and dom elements in source and test code using Object.defineProperty.
But PhantomJS doesn't support this - see issue ariya/phantomjs#13895.
Need to investigate way to drop using Object.defineProperty.

@churkin
Copy link
Contributor

churkin commented Sep 28, 2016

Maybe we should try ianstormtaylor/create-event#9 solution?

@miherlosev
Copy link
Contributor Author

I tried this dark magic and got that it works only for attribute properties.
For event properties it doesn't work.

Step to reproduce:

Test.js

/*Dom element*/ /*Worked*/
console.log('Dom element');
console.log('document.body.attributes.length before redefine:', document.body.attributes.length);
document.body.attributes.constructor.prototype.__defineGetter__('length', function () {return 1000; }); //work
console.log('document.body.attributes.constructor.prototype.__defineGetter__:', document.body.attributes.length);
document.body.attributes.__defineGetter__('length', function () { return 2000; });// don't work
console.log('document.body.attributes.__defineGetter__:',document.body.attributes.length);



/*Event*/
console.log('Event');
var evt = document.createEvent('StorageEvent');

evt.initStorageEvent('storage',false,false,'key','oldValue','newValue', 'http://fabrikam.com/alleged.html', { test: 1 });
console.log('storageArea before redefine:', evt.storageArea);

evt.constructor.prototype.__defineGetter__('storageArea', function () { return window.sessionStorage; });//don't work
console.log('evt.constructor.prototype.__defineGetter__:', evt.storageArea);

evt.constructor.prototype.__defineGetter__.call(evt, 'storageArea', function () { return window.sessionStorage; });//dont't work
console.log('evt.constructor.prototype.__defineGetter__.call:', evt.storageArea);

evt.__defineGetter__('storageArea', function () { return window.sessionStorage; });//dont't work
console.log('evt.__defineGetter__:', evt.storageArea);

evt.__proto__.__defineGetter__('storageArea', function () { return window.sessionStorage; });//dont't work
console.log('evt.__proto__.__defineGetter__:', evt.storageArea);

window.StorageEvent.__defineGetter__.call(evt, 'storageArea', function () { return window.sessionStorage; });//don't work
console.log('window.StorageEvent.__defineGetter__:', evt.storageArea);

@miherlosev
Copy link
Contributor Author

miherlosev commented Sep 30, 2016

I found way to override properties of event object:

var evt = document.createEvent('StorageEvent');

evt.initStorageEvent('storage',false,false,'key','oldValue','newValue', 'http://fabrikam.com/alleged.html', { test: 1 });
console.log('storageArea before redefine:', evt.storageArea);
evt = { get 'storageArea'() { return window.localStorage; } };

@churkin
Copy link
Contributor

churkin commented Sep 30, 2016

@miherlosev how it will help us? :)

miherlosev pushed a commit to miherlosev/testcafe-hammerhead that referenced this issue Oct 5, 2016
@miherlosev
Copy link
Contributor Author

miherlosev commented Oct 5, 2016

Update:
Solution
document.body.attributes.constructor.prototype.__defineGetter__('length', function () {return 1000; }); is wrong.
It override geter on document.body.attributes.constructor.prototype level.
After it all attributes.length wil return 1000 for all dom nodes.

@miherlosev
Copy link
Contributor Author

In total we cannot override properties of DOM elements and event properties in PhantomJS.

@miherlosev
Copy link
Contributor Author

@lock
Copy link

lock bot commented Mar 28, 2019

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

@lock lock bot added the STATE: Auto-locked Issues that were automatically locked by the Lock bot label Mar 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Mar 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
AREA: client REASON: won't fix STATE: Auto-locked Issues that were automatically locked by the Lock bot TYPE: bug
Projects
None yet
Development

No branches or pull requests

3 participants