window["_gaUserPrefs"] = { ioo : function() { return true; } } window["_gaUserPrefs"] = { ioo : function() { return true; } }By creating a script in the page itself, the "_gaUserPrefs" variable is made accessible to the Google Analytics script.
Which is?
Edit: In the interest of saving time, it looks based on your other comment that you're referring to chrome.tabs.executescript, but code executed this way executes as a content script so it doesn't run in the page context and can't communicate with javascript running on the page.
If there's another way of running code in the page without injecting html I'd love to hear about it, though.
browser.tabs.executeScript({
code: `
window["_gaUserPrefs"] = { ioo : function() { return true; } };
`,
allFrames: true, // And maybe this for good measure?
runAt: "document_start",
});
(Spelled browser for WebExtensions, and chrome for most Chromium-based browsers.)This may well be incorrect or incomplete. I’m not properly familiar with the details here. I haven’t made any browser extensions in the WebExtensions era, all I’ve done is plenty of Greasemonkey scripts, where you can use unsafeWindow.eval() for these purposes (and there, if you instead did unsafeWindow._gaUserPrefs = …, you’d run into a SecurityError when the user code tried calling _gaUserPrefs.ioo()).
[0]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/Web...