Is there any way to override localStorage
and sessionStorage
object's methods from content script? I am trying to disallow inline script to clear storages by executing this code from my Chrome extension (content script that runs before page is loaded). The code is:
// ==UserScript==
// @name StorageSaver
// @match http://barbars.org/*
// @grant none
// @run_at startup
// ==/UserScript==
/* jshint -W097 */
'use strict';
// Your code here...
location.href = "javascript: localStorage.clear = function(){alert('local works!');}";
location.href = "javascript: sessionStorage.clear = function(){alert('session works!');}";