function addButton() {
  let controls = document.getElementsByClassName('ytp-right-controls')[0];

  if (!controls)
    return false;

  let button = document.createElement('button');
  button.className = 'ytp-button'
  button.title = 'Picture-in-picture'

  let svgNS = 'http://www.w3.org/2000/svg';

  let svg = document.createElementNS(svgNS, 'svg');
  svg.setAttribute('width', '100%');
  svg.setAttribute('height', '100%');

  let text = document.createElementNS(svgNS, 'text');
  text.textContent = 'PiP';
  text.setAttribute('fill', 'white');
  text.setAttribute('x', '50%');
  text.setAttribute('y', '50%');
  text.setAttribute('text-anchor', 'middle');
  text.setAttribute('dominant-baseline', 'central');

  svg.appendChild(text);
  button.appendChild(svg);

  button.onclick = function() {
    button.style.cursor = 'progress';
    let player = document.getElementById('movie_player').wrappedJSObject;
    player.pauseVideo();
    self.port.emit('pip', {videoId: player.getVideoData()['video_id'],
                           time: player.getCurrentTime(),
                           volume: player.getVolume()});
  };

  controls.appendChild(button);

  self.port.on('done', function() { button.style.cursor = ''; });

  return true;
}

if (!addButton()) {
  let player = document.getElementById('player');
  if (player) {
    let observer = new MutationObserver(function(mutations) {
      mutations.forEach(function(mutation) {
        mutation.addedNodes.forEach(function(node) {
          if (node.id == 'movie_player') {
            observer.disconnect();
            addButton();
          }
        });
      });  
    });
    observer.observe(player, {childList: true, subtree: true});
    setTimeout(function() { observer.disconnect(); }, 10000);
  }
}

@@ -1,16 +1,65 @@
+let player = document.getElementById('player');%0A%0A
 function addButt
@@ -82,24 +82,22 @@
 trols = 
-document
+player
 .getElem
@@ -883,24 +883,26 @@
 s';%0A    let 
+yt
 player = doc
@@ -894,32 +894,30 @@
  ytplayer = 
-document
+player
 .getElementB
@@ -919,28 +919,71 @@
 ment
+s
 By
-Id('movie_player')
+ClassName('html5-video-player')%5B0%5D%0A                         
 .wra
@@ -1000,16 +1000,18 @@
 ct;%0A    
+yt
 player.p
@@ -1059,16 +1059,18 @@
 ideoId: 
+yt
 player.g
@@ -1125,24 +1125,26 @@
       time: 
+yt
 player.getCu
@@ -1191,16 +1191,18 @@
 volume: 
+yt
 player.g
@@ -1343,16 +1343,26 @@
 %0A%7D%0A%0Aif (
+player && 
 !addButt
@@ -1369,80 +1369,12 @@
 on()
-) %7B%0A  let player = document.getElementById('player');%0A  if (player
 ) %7B%0A
-  
   le
@@ -1429,26 +1429,24 @@
 ions) %7B%0A    
-  
 mutations.fo
@@ -1478,18 +1478,16 @@
 %7B%0A      
- 
- 
 mutation
@@ -1531,18 +1531,16 @@
         
-  
 if (node
@@ -1544,29 +1544,48 @@
 ode.
-id == 'movie_
+classList.contains('html5-video-
 player')
  %7B%0A 
@@ -1580,21 +1580,20 @@
 player')
+)
  %7B%0A
-  
         
@@ -1627,18 +1627,16 @@
         
-  
 addButto
@@ -1652,14 +1652,10 @@
     
-  %7D%0A  
+%7D%0A
     
@@ -1668,18 +1668,16 @@
     
-  
 %7D);  %0A  
   %7D)
@@ -1672,24 +1672,20 @@
 %7D);  %0A  
- 
- 
 %7D);%0A
-  
   observ
@@ -1738,18 +1738,16 @@
 true%7D);%0A
-  
   setTim
@@ -1798,14 +1798,10 @@
 10000);%0A
-  %7D%0A
 %7D%0A

Fix PiP button not working for embedded videos