<button class="btn btn-primary" id="button">Display Webcam feed in Picture-in-Picture mode</button>
body {
  padding: 20px;
}
const button = document.getElementById('button');

button.addEventListener('click', async () => {
  const video= document.createElement('video');
  video.muted = true;
  video.srcObject = await navigator.mediaDevices.getUserMedia({ video: true });
  video.play();
  video.addEventListener('loadedmetadata', () => {
    video.requestPictureInPicture()
    .catch(console.error)
  });
});

External CSS

  1. https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css

External JavaScript

This Pen doesn't use any external JavaScript resources.