Skip to content

Commit

Permalink
Don't use copyStyleSheets
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois committed Jun 8, 2023
1 parent 6c4997d commit eb767d4
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -3074,9 +3074,9 @@ class Player extends Component {
return window.documentPictureInPicture.requestWindow({
// The aspect ratio won't be correct, Chrome bug https://crbug.com/1407629
width: this.videoWidth(),
height: this.videoHeight(),
copyStyleSheets: true
height: this.videoHeight()
}).then(pipWindow => {
this.copyStyleSheetsToWindow_(pipWindow);
this.el_.parentNode.insertBefore(pipContainer, this.el_);

pipWindow.document.body.append(this.el_);
Expand Down Expand Up @@ -3109,6 +3109,36 @@ class Player extends Component {
return Promise.reject('No PiP mode is available');
}

/**
* Copy document style sheets to another window.
*
* @param {Window} win
*
* @private
*/
copyStyleSheetsToWindow_(win) {
const allCSS = [...document.styleSheets]
.map((styleSheet) => {
try {
return [...styleSheet.cssRules].map((rule) => rule.cssText).join('');
} catch (e) {
const link = document.createElement('link');

link.rel = 'stylesheet';
link.type = styleSheet.type;
link.media = styleSheet.media;
link.href = styleSheet.href;
win.document.head.appendChild(link);
}
})
.filter(Boolean)
.join('\n');
const style = document.createElement('style');

style.textContent = allCSS;
win.document.head.appendChild(style);
}

/**
* Exit Picture-in-Picture mode.
*
Expand Down

0 comments on commit eb767d4

Please sign in to comment.