Home > front end >  How can I inject my google extension javascript after content gets added by the site's own java
How can I inject my google extension javascript after content gets added by the site's own java

Time:09-26

I am trying to make a google extension that manipulates a video player. The problem is that the video player gets loaded with javascript and the injected javascript is unable to find the element, resulting in an error.

CodePudding user response:

If you use jQuery, there is a very easy way to do this through getScript function. Just add the part of script that you need to be executed after the load and pass it as a parameter to the function.

$.getScript( "app.js" )
  .done(function( script, textStatus ) {
    console.log( textStatus );
    //your remaining code
  })
  .fail(function( jqxhr, settings, exception ) {
    //script fail warning if you want it
});
  • Related