Skip to content

Instantly share code, notes, and snippets.

@mozfreddyb
Last active November 6, 2019 08:55
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mozfreddyb/a096627cc6b2e565a4c2 to your computer and use it in GitHub Desktop.
Save mozfreddyb/a096627cc6b2e565a4c2 to your computer and use it in GitHub Desktop.
inspect assignments to innerHTML
/* inject via
ppmm.loadFrameScript("data:,<js source>", true);
(where ppmm is the message manager, e.g. in shell.js)
framescript documentation explains why this works[1] and
the message manager docs[2] explain that the parent process
manager defined as ppmm in shell.js[3] can be used.
[1] https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Frame_script_loading_and_lifetime
[2] https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Message_manager_overview
[3] https://dxr.mozilla.org/mozilla-central/source/b2g/chrome/content/shell.js
*/
(function () {
var setter = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML').set;
Object.defineProperty(Element.prototype, 'innerHTML', {
set: function innerHTML_Setter(val) {
console.group();
console.log('innerHTML on Object:', this, );
console.log('Value:', JSON.stringify(val));
var stack = new Error().stack;
// Remove this function from the stack:
stack = stack.trim().split('\n').slice(1).join(' <- ')
console.log('Stack: ', stack)
console.groupEnd();
// call original innerHTML setter:
return setter.call(this, val)
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment