Skip to content

Add offscreen user media sample#1056

Closed
aakash232 wants to merge 2 commits into
GoogleChrome:mainfrom
aakash232:offscreen-user-media-sample
Closed

Add offscreen user media sample#1056
aakash232 wants to merge 2 commits into
GoogleChrome:mainfrom
aakash232:offscreen-user-media-sample

Conversation

@aakash232

@aakash232 aakash232 commented Dec 20, 2023

Copy link
Copy Markdown

This recipe shows how to use User Media in an Extension Service Worker using the Offscreen document.

The extension aims to capture audio from the user in the context of extension (globally) via a media recorder in the offscreen document.

Aims to add a new sample fixing the issue : MV3 user's mic and cam permissions using iframe
Fixes #821

@aakash232

aakash232 commented Dec 20, 2023

Copy link
Copy Markdown
Author

@patrickkettner
As discussed on the mail, raised the PR for the sample.
Please review the same.

@aakash232

Copy link
Copy Markdown
Author

@oliverdunk
As discussed on the mail, raised the PR for the sample.
Please review and guide me for the same.

"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["contentScript.js"]

@sorokinvj sorokinvj May 26, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do just this

Suggested change
"js": ["contentScript.js"]
"js": ["contentScript.js", "requestPermissions.js"]

and run it without all the fuss with iframes, messaging to offscreen and back

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

however I still get permission in prompt state, so I am probably missing something from your code

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sorokinvj

#821 : The reason for requesting mic and cam permissions inside the iframe is because we want to ask for the permissions on behalf of the extension app (eg -> "[myExtension] wants to Use" instead of "www.google.com wants to use your camera and microphone") and hold onto the permissions across all tabs, only asking once for the permissions.


Your suggestion of injecting CS directly via manifest will not help in accomplishing above goal. But will definitely ease around the fuss if you don't need it in the context of your extension.

Attaching a snapshot for reference how your suggested code will ask for permissions.

image

Let me know if I am missing out something in your proposed flow.
Thanks.

@patrickkettner

Copy link
Copy Markdown
Collaborator

hi @aakash232, I am really sorry this never got a proper review. your PR proved out the core idea here (grant mic to the extension origin from a page, record in the offscreen document) and #1717 builds on exactly that, in a smaller shape that avoids the all_urls content script. closing in favor of that one, and thank you for working out the hard part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MV3 user's mic and cam permissions using iframe

4 participants