Closed mattveraldi closed 1 year ago
Investigation notes: Reason for this is because this libray does some prototype hacking internally, which can be tracked down to this minimal reproducible, imagine this below is what we do internally:
const myTest = {}
// without __proto__ it works as expected.
Object.defineProperties(myTest.__proto__, {
data: {
get: () => 42,
set: () => {},
}
})
// What we do internally to serialise results.
console.log(Object.getOwnPropertyDescriptors(myTest), Object.keys(Object.keys(myTest)))
I recommend for now to access the 'data' property manually directly. Would that work for you?
Investigation notes: Reason for this is because this libray does some prototype hacking internally, which can be tracked down to this minimal reproducible, imagine this below is what we do internally:
const myTest = {} // without __proto__ it works as expected. Object.defineProperties(myTest.__proto__, { data: { get: () => 42, set: () => {}, } }) // What we do internally to serialise results. console.log(Object.getOwnPropertyDescriptors(myTest), Object.keys(Object.keys(myTest)))
I recommend for now to access the 'data' property manually directly. Would that work for you?
I see the problem now... What I am doing at the moment is adding "data" manually in the return statement of the evaluate
method, but that means that I have to do it for each "getter" in order to have a generic utility function for gojs nodes...
Is there any possible workaround to this?
There is unfortunately no easy way around this problem. Keep in mind that the JavaScript inside the page gets serialised with the Node.js runtime, see here: https://playwright.dev/docs/evaluating
So we do a best effort which fails in case of deep prototype getters.
Closing by that for now, since a workaround for this would be to return a property explicitly.
@mxschmitt Ok thank you, just to know if I understood correctly... this the serializer that does the "prototype hacking" you was referring to?
The prototype hacking with the getters is done with this gojs library. I didn't find their source online, but internally they do things like ma.Object.defineProperties(W.prototype, {
(minified source). And we internally serialise using this while Object.keys does not work for this library.
Thank you!
System info
Source code
Config file
Test file (self-contained)
Steps
Expected
node.data
should work outside of the evaluate context as well as inside it.Actual
node.data
is undefined when accessed outside the evaluate context, but it has other properties.