Javascript, Chrome Extension: Overriding Cookie Getter And Setter
Solution 1:
I think you're trying hard to reinvent the wheel here. Quoting the docs:
Use the
chrome.cookiesAPI to query and modify cookies, and to be notified when they change.
I get it that sometimes you want to prevent it in the first place, and let's take a look at that as well, but you've got to understand how cookies work. There are 2 kinds of cookie set operations:
By the client, by
document.cookiemanipulation. Then your approach may help, but to ensure that the cookie is intercepted you cannot rely on programmatic injection, it is indeed too slow. You need to declare it in the manifest with a properrun_atparameter:"content_scripts":[{"matches":["<all_urls>"],"js":["cookiescript.js"],"run_at":"document_start"}]This will ensure your code executes before anything else on the page (before there is even anything in the DOM).
By the server as part of the HTTP response. It may even be HTTP-Only cookie that's not exposed to
document.cookie.You can intercept that as well, but you need to use
webRequestfor that, specifically a blocking response toonHeadersReceivedcan examine and modify headers that set cookies, and a blocking response toonBeforeSendHeaderscan modify cookies reported to the server.
Post a Comment for "Javascript, Chrome Extension: Overriding Cookie Getter And Setter"