title: How to call the callback function within selenium execute_async_script from python
body: <p>i am scraping one website, there is audio playing from the webpage, i want to know when will the audio finish playing, so i add event listener to the audio webElement to monitor 'onEnded' event to fire, and i want to get noticed from the callback() function within driver.execute_async_script.  </p>
  
  <p>but i always get error </p>
  
  <p><code>TypeError: &lt;function MissionContentItemHelper.audio_play_end at 0x10f3b7b70&gt; is not JSON serializable.</code></p>
  
  <p>my questions are:</p>
  
  <p>1.does arguments[arguments.length - 1] refer to self.audio_play_end ?</p>
  
  <p>2.why the error output is about 'MissionContentItemHelper.audio_play_end is not JSON serializable'? i can't see any clue between MissionContentItemHelper.audio_play_end and JSON.</p>
  
  <p>3.is the way calling audio_play_end correct?</p>
  
  <pre><code>class MissionContentItemHelper: 
      def sleep(self):
          audio = self.browser.find_element_by_css_selector('#audio')
          self.browser.execute_async_script("""
              var audio = arguments[0];
              callback = arguments[arguments.length - 1];
              audio.addEventListener("ended", function(_event) {
                  callback();
              }
          """, audio, self.audio_play_end)
  
      @staticmethod
      def audio_play_end():
          print('the audio finished playing...')
  </code></pre>