WICG / document-picture-in-picture

https://wicg.github.io/document-picture-in-picture/
Other
58 stars 9 forks source link

What does "Document PiP requires user activation" mean? #96

Closed pandyama closed 1 year ago

pandyama commented 1 year ago

I am trying to trigger the Pip window to open up on a blur event i.e when the user navigates away from the chrome tab, I want to trigger the Pip. I want to know if this is something possible? And, I wanna understand what "Document PiP requires user activation" exception means, thanks!

steimelchrome commented 1 year ago

"user activation" generally means a user clicked something on your page. You cannot currently do what you are trying to do, but Chrome is currently looking into using an 'enterpictureinpicture' MediaSessionAction to allow that scenario to happen (you would register for that action and Chrome would fire it in specific cases when a user navigates away from your tab)

pandyama commented 1 year ago

@steimelchrome oh ok gotcha, thanks for the quick response... & where can i see the timeline for that feature's release? or if you just happen to know, that'd be good info to have

steimelchrome commented 1 year ago

We're hoping for an initial launch in M120 that would only cover cases where the website is currently using camera or microphone (so that your VC calls can automatically PiP when you go to another tab). We will follow that up with more use cases (e.g. video playback), but I'm not sure exactly when that'd be. Does your use case use camera or microphone and/or do you have a video playing when the user switches tabs?

pandyama commented 1 year ago

@steimelchrome Yaa we use microphone for audio recording, no video for our use-case. Also what does VC calls mean? not familiar w that short form

steimelchrome commented 1 year ago

VC stands for video conferencing, so something like Zoom. If you are using the users microphone in your use case, then you should be able to work with the initial launch (hopefully M120)

pandyama commented 1 year ago

Thanks @steimelchrome will keep an eye out for M120's release schedule!

steimelchrome commented 1 year ago

Hey fyi in Chrome Canary 120.0.6050.0 and later, you should be able to play around with this now.

Enable the flag at chrome://flags/#media-session-enter-picture-in-picture

You can see a test page here: https://steimelchrome.github.io/autopip.html

Opening camera and then switching tabs allows the page to trigger video or document pip without user activation (there is a per-site setting for it, so the user can allow/block this functionality)

pandyama commented 1 year ago

@steimelchrome thanks, is there any sample code available anywhere to reference it & see how it works

steimelchrome commented 1 year ago

If you right-click on the page I linked above (https://steimelchrome.github.io/autopip.html) and click "View Page Source" it should show the underlying code. Most importantly, registering for the media session action handler like this:

navigator.mediaSession.setActionHandler('enterpictureinpicture', enterPip);
pandyama commented 1 year ago

Gotcha, I just assumed page source may not have it, but it is raw html so makes sense... thanks!

pandyama commented 1 year ago

@steimelchrome currently i see this error msg when I open the github.io page, I am guessing that's because my Chrome version is 117, and as you mentioned this is available in 120

TypeError: Failed to execute 'setActionHandler' on 'MediaSession': The provided value 'enterpictureinpicture' is not a valid enum value of type MediaSessionAction

steimelchrome commented 1 year ago

Yep, you'll need an updated Chrome Canary (which will be version 120) and then you can enable the flag at chrome://flags/#media-session-enter-picture-in-picture. Without that flag, you'll see that error message

pandyama commented 1 year ago

sweet, thanks!

tomayac commented 1 year ago

TypeError: Failed to execute 'setActionHandler' on 'MediaSession': The provided value 'enterpictureinpicture' is not a valid enum value of type MediaSessionAction

(See https://github.com/w3c/mediasession/issues/228 where detecting supported action handlers is being discussed.)

pandyama commented 1 year ago

thanks @tomayac will take a look at that