Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to override document.cookie in WebKit?

In Firefox it's possible using the following...

HTMLDocument.prototype.__defineGetter__("cookie",function (){return "foo=bar";});
HTMLDocument.prototype.__defineSetter__("cookie",function (){});

This doesn't cause any errors in WebKit, and WebKit definitely supports __defineGetter__ and __defineSetter__, but it doesn't work. Guessing WebKit is protecting that property somehow.

So, any ideas of how to achieve the same effect in WebKit?

like image 611
netnichols Avatar asked Jun 14 '09 08:06

netnichols


1 Answers

Have you tried do define the getter/setter pair on the document object itself, instead on the prototype?

document.__defineGetter__("cookie", function() {} );
document.__defineSetter__("cookie", function() {} );

I know it shouldn't matter, but I don't underestimate browser quirks. Even with WebKit.

Update

I've done some tests in Chrome 2 and it appears that it only allows defining a setter. Anyway, I'm not sure how valid this observation is to WebKit, as Google Chrome uses a different JavaScript interpreter than WebKit.

like image 98
Ionuț G. Stan Avatar answered Sep 28 '22 08:09

Ionuț G. Stan