0

is it possible to get what on click function is binded to the element in vanillaJS and reuse that? I want to write google extension and I would need to 'prebind' my onclick function to then element, do some work and the call the original function. Is that possible?

  • So far it sounds like you can simply use addEventListener with the third parameter being `true` to add the listener in the capture phase that runs before the normal phase. If you really want to spoof the site's click handler you'll have to do it in [page context](/a/9517879). – wOxxOm Mar 14 '21 at 12:09
  • Oh seems great. But I came up with another idea. This is how I can intercept ajax call `(function(send) { XMLHttpRequest.prototype.send = function(body) { console.log(body) send.call(this, body); }; })(XMLHttpRequest.prototype.send);` But the problem is I can't recognise what caused that call. I would need to know url or anything that has unique id. Is that possible? –  Mar 14 '21 at 12:14
  • Intercept `open` instead of (or in addition to) `send` so you will have the url parameter. – wOxxOm Mar 14 '21 at 12:23

0 Answers0