Re: [mediacapture-region] Why expose produceCropTarget at MediaDevices level? (#11)

We still [need consensus](https://docs.google.com/presentation/d/15iAIhzpaA6reKJBL-ecgYtic6ZKHEpKL5OK_sExTllc/edit#slide=id.g121e6504fd1_3_0) on API shape for cropping capture of own viewport (tab) to an element, so let me try this thought experiment, and solicit broader API design input. cc @annevk , @domenic

What's the simplest API for web developers? We agree in https://github.com/w3c/mediacapture-region/issues/19 that when the element is in the same document, the answer is:
```js
const element = document.getElementById("foo");
await track.cropTo(element);
``` 
So that's the ideal API. What's getting in the way of that: the element to crop to may be in a different-origin document, and we can't postMessage element, yet nothing short of the element will do (since the element may visually move):
```js
// b.com/iframe.html
const element = document.getElementById("foo");
parent.postMessage(element, "*"); // won't work!

// a.com/main.html
window.onmessage = async ({data: element}) => await track.cropTo(element);
``` 
We've agreed the solution is to postMessage a [weak reference](https://w3c.github.io/mediacapture-region/#dfn-create-a-croptarget) to the element instead. I think the simplest API for that is:
 ```js
// b.com/iframe.html
const element = document.getElementById("foo");
parent.postMessage(element.weakRef, "*");

// a.com/main.html
window.onmessage = async ({data: elementWeakRef}) => await track.cropTo(elementWeakRef);
```
...but instead we have:
```js
// b.com/iframe.html
const element = document.getElementById("foo");
parent.postMessage(await navigator.mediaDevices.produceCropTarget(element), "*");

// a.com/main.html
window.onmessage = async ({data: cropTarget}) => await track.cropTo(cropTarget);
```
...which seems more complex than it needs to be:
 1. An irrelevant object is involved (mediaDevices)
 2. An asynchronous method is used where a synchronous attribute should suffice #17
 3. Naming of a potentially useful weak reference concept is (too?) narrowly scoped to cropping.

Thoughts?

-- 
GitHub Notification of comment by jan-ivar
Please view or discuss this issue at https://github.com/w3c/mediacapture-region/issues/11#issuecomment-1112514784 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 28 April 2022 18:11:36 UTC