Reputation: 21
I am trying to override document.cookie in my Chrome extension and I'm having a lot of trouble getting the original document.cookie functionality to work at the same time. Currently I have this:
var _cookie = document.cookie;
document.__defineSetter__("cookie", function(the_cookie) {_cookie=the_cookie;} );
document.__defineGetter__("cookie", function() {return _cookie;} );
I am injecting the JS from a content script using the technique from here.
The behavior I'm seeing is that my re-defined setter and getter get called, but the original function is no longer working. For example, I can check _cookie and document.cookie using the Developer Tools and see that they have the same, expected value, but no cookies ever appear in Chrome's cookie store.
Can anyone tell me how I am breaking the original document.cookie functionality? Is the problem that document.cookie is a property, so I'm not actually getting a pointer to the original setter?
Upvotes: 2
Views: 4849
Reputation: 28076
var _cookie = document.cookie;
is not saving the original getter and setter for cookie
, it is just calling the getter and saving the result.
This page (original link, now broken) has an example of how to save the cookie setter and getter:
var cookie_setter = document.__lookupSetter__ ('cookie');
var cookie_getter = document.__lookupGetter__ ('cookie');
Upvotes: 3
Reputation: 1350
You have redefined the orignal cookie getter and setter functions, and there might be a chance that you could have forgotten an important part or implementation of the original functions in the new functions
Upvotes: 1