mirror of
https://codeberg.org/vlw/pip-canvas.git
synced 2025-09-13 18:33:41 +02:00
fix: wait for media and cross-origin error
This commit is contained in:
parent
97e9a02175
commit
366867f1f3
1 changed files with 15 additions and 2 deletions
|
@ -15,6 +15,17 @@ export class PipCanvas {
|
|||
|
||||
// Create from image
|
||||
HTMLImageElement() {
|
||||
const img = new URL(this.source.src);
|
||||
const isDataUrl = new RegExp("^\s*data:");
|
||||
|
||||
// Can not open cross-origin images
|
||||
if (!isDataUrl.test(this.source.src) && (img.origin !== window.location.origin)) {
|
||||
const error = "PipCanvas: This cross-origin image can not be opened in PIP";
|
||||
|
||||
alert(error);
|
||||
throw new Error(error);
|
||||
}
|
||||
|
||||
this.ctx.width = this.ctx.canvas.width = this.source.width;
|
||||
this.ctx.height = this.ctx.canvas.height = this.source.height;
|
||||
|
||||
|
@ -23,7 +34,9 @@ export class PipCanvas {
|
|||
|
||||
// Open PIP
|
||||
open() {
|
||||
this.video.addEventListener("canplaythrough",() => {
|
||||
this.video.play();
|
||||
this.video.requestPictureInPicture();
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue