-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chrome tabCapture example #627
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I am trying to capture the tab video for later edit share and upload |
HI @ddenis1994, @guest271314
in the content script, I'm getting |
This comment was marked as off-topic.
This comment was marked as off-topic.
@guest271314 I'm trying to capture audio in any live web based meeting conference app playing in a chrome tab. I'm able to capture user's audio input but I also need to capture the system audio. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
@guest271314 By system audio, I meant the output audio of the tab. Like a speaker in a zoom meeting. |
I tried using |
This comment was marked as off-topic.
This comment was marked as off-topic.
There isn't any
|
This comment was marked as off-topic.
This comment was marked as off-topic.
Is there anyway to start capturing the current tab directly (video only)? If I understand correctly |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Okay I finally got a working prototype with the same approach as said in OP's comment: #627 (comment).
With this approach, capture starts immediately on the active tab without the media select popup window. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I'm sorry, I had deleted those code, I cannot post them now. I had test #627 (comment) on my brower, It works. Thank you. |
@LiuShuaiyi @ddenis1994 After I use the method you mentioned, I can successfully get the audio, but the page will become silent, I want it to continue to play the sound, do you have a way to do this |
@guest271314 @ddenis1994 @donething test-the-audio.zip manifest.json {
"name": "Test the audio",
"version": "1.0.0",
"description": "Sound can be recorded, but the tab is muted",
"manifest_version": 3,
"permissions": ["tabs", "activeTab", "scripting", "tabCapture"],
"action": {
"default_popup": "popup.html"
}
} popup.js // Get the current id
chrome.tabs.query(
{
active: true,
currentWindow: true,
},
(tabs) => {
const tabId = tabs[0].id;
// Get the streamId
chrome.tabCapture.getMediaStreamId(
{
consumerTabId: tabId,
},
(streamId) => {
// Load the content.js
chrome.scripting.executeScript(
{
target: { tabId },
files: ["content.js"],
},
() => {
// Send the streamId to the tab
chrome.tabs.sendMessage(tabId, streamId);
}
);
}
);
}
); chrome.runtime.onMessage.addListener(async (streamId) => {
console.log("streamId--->", streamId);
// Get the stream
const stream = await navigator.mediaDevices.getUserMedia({
audio: {
mandatory: {
chromeMediaSource: "tab",
chromeMediaSourceId: streamId,
echoCancellation: true,
},
},
});
console.log("stream--->", stream);
// Now I successfully recorded the sound, but the page is also muted
// -------------------------------------------------------------------
// Connected to an audio player, but still no sound, why ?????????????
// -------------------------------------------------------------------
const audioContext = new AudioContext();
const mediaStream = audioContext.createMediaStreamSource(stream);
mediaStream.connect(audioContext.destination);
}); |
This comment was marked as off-topic.
This comment was marked as off-topic.
The following error can be ignored
I use the code you said, the audio can be successfully recorded, and the page can play the sound normally But I don't want the browser to evoke the tab selection popup again, I want to record directly on the current page {
"name": "Test the audio",
"version": "1.0.0",
"description": "Sound can be recorded, but the tab is muted",
"manifest_version": 3,
"permissions": ["tabs", "activeTab", "scripting", "desktopCapture"],
"action": {
"default_popup": "popup.html"
}
} popup.js // Get the current id
chrome.tabs.query(
{
active: true,
currentWindow: true,
},
(tabs) => {
const tab = tabs[0];
const tabId = tab.id;
// Get the streamId from desktopCapture
chrome.desktopCapture.chooseDesktopMedia(
["tab", "audio"],
tab,
(streamId) => {
// Load the content.js
chrome.scripting.executeScript(
{
target: { tabId },
files: ["content.js"],
},
() => {
// Send the streamId to the tab
chrome.tabs.sendMessage(tabId, streamId);
}
);
}
);
}
); content.js const audioContext = new AudioContext();
chrome.runtime.onMessage.addListener(async (streamId) => {
console.log("streamId--->", streamId);
// Get the stream
const stream = await navigator.mediaDevices.getUserMedia({
video: {
mandatory: {
chromeMediaSource: "screen",
chromeMediaSourceId: streamId,
},
},
audio: {
mandatory: {
chromeMediaSource: "desktop",
chromeMediaSourceId: streamId,
},
},
});
stream.removeTrack(stream.getVideoTracks()[0]);
console.log("stream--->", stream);
// Here you can successfully record the sound, and the page will not mute
// -------------------------------------------
// If I don't create the recorder node, the recording is garbled, it's weird
// -------------------------------------------
const mediaStream = audioContext.createMediaStreamSource(stream);
const recorder = audioContext.createScriptProcessor(0, 1, 1);
recorder.onaudioprocess = (event) => {
const inputData = event.inputBuffer.getChannelData(0);
console.log("audio--->", inputData);
};
mediaStream.connect(recorder);
recorder.connect(audioContext.destination);
}); |
This comment was marked as off-topic.
This comment was marked as off-topic.
@guest271314 ok, thanks a lot for your help |
This comment was marked as off-topic.
This comment was marked as off-topic.
Using @zhw2590582 's work as a reference (https://github.com/zhw2590582/chrome-audio-capture) I re-implemented audio capture when I upgraded to MV3 (https://github.com/killergerbah/asbplayer/blob/main/extension/src/services/BackgroundPageAudioRecorder.ts). The trick is in recognizing that you can access the tabCapture API from an inactive tab created from HTML packaged with the extension. The UX is still worse than MV2 since you need the extra tab but with some effort it's possible to keep that tab somewhat "invisible." |
But then the original tab sound is muted while recording and there's no way to unmute it. The sound is present in the recording, though. This approach is unusable for any use case I can think of. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Apologies if I wasn't clear enough - I meant "the original live sound of the tab being recorded" is being muted. I've posted a detailed description of the bug on the Chromium Extensions group. |
This comment was marked as off-topic.
This comment was marked as off-topic.
@guest271314 Here you go, the more detailed description on StackOverflow. I only want to use getDisplayMedia/desktopCapture as a last resort because of the intrusive prompts. I've also tried to record the speaker output, but that failed too. I see you've also contributed to that exploration yourself, maybe you can provide more details on how you managed to get it working. Didn't work for me. |
This comment was marked as off-topic.
This comment was marked as off-topic.
Ok, so not working. I aim to upload this to the store, so any client-side changes are out of the question. How about the bug I posted here, what do you think about that? Can you reproduce it yourself? In essence passing a stream id from an iframe to a content script, then using getUserMedia to get that stream, resulting in a good recording but a muted tab. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I will provide an example as soon as I'm able to. I plan on launching this
on the store, so no client-side modifications, including launching with
flags.
…On Fri, Dec 30, 2022, 16:22 guest271314 ***@***.***> wrote:
@Deewde <https://github.com/Deewde> To avoid prompts altogether you can
1. Set the default audio device that you intend to capture;
2. Launch Chrome with --use-fake-ui-for-media-stream flag
I am not sure what is causing the muting behaviour you described without a
repoducible example.
—
Reply to this email directly, view it on GitHub
<#627 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHKFQZQNHN3BHJMGJWERQBTWP3V2RANCNFSM5CAGIHZQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
This comment was marked as off-topic.
This comment was marked as off-topic.
I already posted a how to reproduce on StackOverflow, but you require a
full-working minimal example, which I can't provide without putting in some
time. I will, though.
…On Fri, Dec 30, 2022, 16:58 guest271314 ***@***.***> wrote:
I will provide an example as soon as I'm able to.
You should be able to post the code you have so far that causes the muting
behaviour.
Note, a user can modify the extension once it is on their machine.
—
Reply to this email directly, view it on GitHub
<#627 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHKFQZTUAAEX32SKBG3J56DWP32ANANCNFSM5CAGIHZQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@mirkonasato you can use this example I created: https://github.com/wireworks-app/chrome-screen-recording |
was anyone able to solve this issue to keep the tab unmuted live while it records tab audio? |
How do we get access to Media from the user's microphone using the offscreen API?
Currently, this throws a NotAllowedError and we are not sure how to proceed. |
I am having the exact same issue. I am able to successfully use an offscreen document to capture and record a tab. However, I want to include the users commentary from their microphone while using that tab and I can't figure out how to get a stream of the microphone. If I could get the stream I could mix the tracks with the tracks from the tab capture. However calling the following code in the offscreen document produces a NotAllowedError. const microphoneMedia = await navigator.mediaDevices.getUserMedia({
audio: true,
video: false,
}); Is there a way to get a streamId of the microphone to pass to the offscreen document similar to the same way we're getting a stream id for the tab? |
you can get microphone stream on offscreen if user had previously consented to microphone permission for your extension on my demo using an action popup, I setup a popup.html with a script tag sourcing from popup.js, and in popup.js I had a getUserMedia({ audio: true }) call, which triggered the permission prompt my-extension wants to use your microphone on first time after I consented, I was able to call getUserMedia({ audio: true }) and successfully get a microphne stream; before consenting, I would get a DOMException: Failed due to shutdown apparently offscreen documents can't invoke permission prompt, so it must be asked somewhere else, be it in an action popup, iframe inside a content script, options page, or whatever context that can invoke permissions prompt on behalf of your extension (note that it must be get on behalf of your extension, if you ask it on a content script for example, you'll get "google.com wants to use your microphone" and that won't give your offscreen the ability to get microphone stream) |
@juxnpxblo would you be willing to file a bug on crbug about that? i.e. offscreen document not showing a permission prompt (but working if permission was already given? |
@juxnpxblo ping |
@LiuShuaiyi are you able to record the content of the tab using
|
Did anybody manage to get @LiuShuaiyi 's solution working? For me the part where I send the streamID to my content script and try to capture the screen, I get the `if(request.action === "startRecording"){
` |
Yes I managed to make it work, you have to add
|
Hey @aziz-boudi4 but I am not using TypeScript. How does this work in JavaScript? P.S. It didn't work since my code is in JavaScript |
The previous issue got fixed. The current issues are the following.
|
hi am tiring to use the tabCapture API without success for a few days now
what I tried
running the tab capture in the content - results in undefined to the API
running the tab capture inside an iframe that the src is HTML that accessible to the extension (iFrame.src = chrome.runtime.getURL("gif.html");) -result in an error when the user clicks on a button to initiate the recorded Error starting tab capture
maybe someone can share code example for using the tab capture API in manifest version 3
thanks
The text was updated successfully, but these errors were encountered: