title: Get YouTube Live Embed Chat On Mobile Devices
body: <p>The YouTube livestream chat works on the desktop by using </p>
  
  <pre><code>&lt;iframe src="https://youtube.com/live_chat?v=[LIVE VIDEO ID]"&gt;&lt;/iframe&gt;
  </code></pre>
  
  <p>But, it doesn't appear on mobile using the same code. </p>
  
  <p>I've narrowed the problem down to what seems to be a User-Agent issue. When testing the mobile version of the site with Chrome on a desktop (inspect element > phone icon > iphonex > refresh), it still doesn't show up. But when I change the user agent on chromes iPhone (inspect element-ed) version and refresh, it shows up (inspect element > network conditions > user agent).</p>
  
  <p>To backup, this claim about the User-Agent, the only other thread I could find on the internet about this (found <a href="https://stackoverflow.com/questions/48244906/youtube-embed-live-chat-is-not-working-on-mobile-recently">Here</a>) talks about how it fixed it for him (or maybe not?). When I tried implementing his solution, I got no results.</p>
  
  <p>I've tried to change the User-Agent using PHP and JavaScript now, neither of them working on an iPhone's Safari or the Google Chrome iPhone (inspect element-ed). </p>
  
  <p>I've also tried re-creating the embed with PHP, but it failed with multiple 404 errors. </p>
  
  <p>It's odd because when I change the User-Agent through the inspect element-ed version, it works. </p>
  
  <p>I've tried changing the User-Agent in JavaScript with</p>
  
  <pre><code>//First Try
  Object.defineProperty(navigator, 'userAgent', {
  get: function () { return 'Mozilla/5.0 (Windows NT 6.2; WOW64; 
  rv:28.0) Gecko/20100101 Firefox/28.0)'; }});
  
  //Second Try
  navigator.__defineGetter__('userAgent', function () {
  return "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0)"});
  
  //Third Try
  var xhr = new XMLHttpRequest(...);
  xhr.setRequestHeader("User-Agent","test");
  </code></pre>
  
  <p>I've tried changing it with PHP with</p>
  
  <pre><code>ini_set('user_agent', 'MyBrowser v42.0.4711');
  </code></pre>
  
  <p>This leads me to believe that I'm setting it wrong in all of these, there's another factor I'm forgetting, or mobile isn't capable of supporting it.</p>
  
  <p>But, if mobile wasn't capable of setting it, it would show me a message. When setting the User-Agent in PHP, nothing happened, until I requested the desktop site which gave me a message along the lines of</p>
  
  <pre><code>Your browser is too old to use livechat
  </code></pre>
  
  <p>Not sure if it really is, or it's just the User-Agent. </p>
  
  <p>I'm open to using the YouTubeLivestreamingChat API, but I can't really figure out how to use it (specifically what a part is). I'm also open to a solution in PHP or JavaScript.</p>