I\'m trying to change the variable in a page using a userscript. I know that in the source code there is a variable
var smilies = false;
I
In Content scripts (Chrome extensions), there's a strict separation between the page's global window
object, and the content script's global object.
The final Content script's code:
// This function is going to be stringified, and injected in the page
var code = function() {
// window is identical to the page's window, since this script is injected
Object.defineProperty(window, 'smilies', {
value: true
});
// Or simply: window.smilies = true;
};
var script = document.createElement('script');
script.textContent = '(' + code + ')()';
(document.head||document.documentElement).appendChild(script);
script.parentNode.removeChild(script);