0

I'm writing a chrome extension for a specific website. That website has a javascript function like this:

function showBox(someUnrelatedParameter){
    // ...
    $('#something').appear({duration: 0.5}};
    // ...
    return false;
}

And some buttons on the website have onclick="showBox(...)" to trigger this function.

Now what I basically want to do is to speed this up, i.e. by making #something appear in 0.1 instead of 0.5. Is it somehow possible to inject that javascript function with my chrome extension to make it use a different duration?


Otherwise, I have a somewhat fishy idea that I could try to copy that entire function from the website, and provide it in my extension like this:

function showBoxNew(someUnrelatedParameter){
    // ...
    $('#something').appear({duration: 0.1}};
    // ...
    return false;
}

And then manipulate the DOM to replace all onclick="showBox with onclick="showBoxNew. The problem with this is that any changes that the website might do to that function are then lost with this extension, even though I just want to change the duration.

Any better ways?

user2015253
  • 1,263
  • 4
  • 14
  • 25
  • 1
    You cannot change the body of an existing function. The best you can do is overwrite it, but that will depend on whether your extension can "see" the function, depending on whether it is globally accessible. – Mitya Jul 30 '20 at 16:41
  • *Is it somehow possible to inject that javascript function with my chrome extension to make it use a different duration?* I certainly hope not! Imagine the security nightmares it you could! – Scott Marcus Jul 30 '20 at 16:41
  • 1
    It is possible. It is one of the core abilities of extensions. Simply put your code in a script element, [more info](/a/9517879). Judging by the fact that the function is used in HTML it means the function is global so you can easily overwrite it or extend it e.g. by saving the original and calling it several times in your own override. – wOxxOm Jul 30 '20 at 16:58
  • @ScottMarcus Out of curiosity, how would injecting a function be more insecure than overwriting the function with a customized one? – user2015253 Jul 30 '20 at 23:44

0 Answers0