From 961028b1bf0a963717a84c83ba242fd49522d65c Mon Sep 17 00:00:00 2001 From: Xuezhou Dai Date: Thu, 1 Jun 2023 17:51:54 +0800 Subject: [PATCH] Add tabCapture sample (#933) * Add tabCapture sample * Add README * Update receiver.html * Fix variable loss caused by idle * Use windows.create * Remove unnecessary logs * Update README * Update api-samples/tabCapture/README.md Co-authored-by: Oliver Dunk * Update api-samples/tabCapture/README.md Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com> * Update api-samples/tabCapture/README.md Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com> * Update api-samples/tabCapture/README.md Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com> * Rename background.js * Remove unnecessary async function * Move the script to the body * Update api-samples/tabCapture/README.md Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com> * Update README.md * Update api-samples/tabCapture/manifest.json Co-authored-by: Oliver Dunk --------- Co-authored-by: Oliver Dunk Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com> --- api-samples/tabCapture/README.md | 21 ++++++ api-samples/tabCapture/icon.png | Bin 0 -> 3041 bytes api-samples/tabCapture/manifest.json | 13 ++++ api-samples/tabCapture/receiver.html | 15 ++++ api-samples/tabCapture/receiver.js | 91 +++++++++++++++++++++++ api-samples/tabCapture/service-worker.js | 36 +++++++++ 6 files changed, 176 insertions(+) create mode 100644 api-samples/tabCapture/README.md create mode 100644 api-samples/tabCapture/icon.png create mode 100644 api-samples/tabCapture/manifest.json create mode 100644 api-samples/tabCapture/receiver.html create mode 100644 api-samples/tabCapture/receiver.js create mode 100644 api-samples/tabCapture/service-worker.js diff --git a/api-samples/tabCapture/README.md b/api-samples/tabCapture/README.md new file mode 100644 index 00000000..6f39d009 --- /dev/null +++ b/api-samples/tabCapture/README.md @@ -0,0 +1,21 @@ +# chrome.tabCapture + +A sample that demonstrates how to use the [`chrome.tabCapture`](https://developer.chrome.com/docs/extensions/reference/tabCapture/) API. + +## Overview + +In this sample, the `chrome.tabCapture` API captures the contents of the active tab. The captured stream is displayed in a new window. + +## Implementation Notes + +Use [`tabCapture.getMediaStreamId`](https://developer.chrome.com/docs/extensions/reference/tabCapture/#method-getMediaStreamId) to capture specific tabs. + +The `targetTabId` and `consumerTabId` are obtained in the Service Worker, and then passed to the receiver page through the [`tabs.sendMessage`](https://developer.chrome.com/docs/extensions/reference/tabs/#method-sendMessage) method. + +See the [Audio recording and Screen capture guide](https://developer.chrome.com/docs/extensions/mv3/screen_capture/#audio-and-video) for a more detailed implementation. + +## Running this extension + +1. Clone this repository. +2. Load this directory in Chrome as an [unpacked extension](https://developer.chrome.com/docs/extensions/mv3/getstarted/development-basics/#load-unpacked). +3. Click the extension's action icon. diff --git a/api-samples/tabCapture/icon.png b/api-samples/tabCapture/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a49189cf98722208000caa1a69795c2f036cb8bc GIT binary patch literal 3041 zcmV<73m)`|P)4Tx0C?J+Q)g6D=@vcr-tj1^HV42lZa2jn55j)S9!ipu-pd!uXCy!YnK{> z2n?1;Gf_2w45>mM5#WQz#Kz&|EGkvK~TfD`~gdX7S-06<0ofSs5oQvjd@0AR~wV&ec% zEdXFAf9BHwfSvf6djSAjlpz%XppgI|6J>}*0BAb^tj|`8MF3bZ02F3R#5n-iEdVe{ zS7t~6u(trf&JYW-00;~KFj0twDF6g}0AR=?BX|IWnE(_<@>e|ZE3OddDgXd@nX){& zBsoQaTL>+22Uk}v9w^R97b_GtVFF>AKrX_0nHe&HG!NkO%m4tOkrff(gY*4(&JM25 z&Nhy=4qq+mzXtyzVq)X|<DpKGaQJ>aJVl|9x!Kv}EM4F8AGNmGkLXs)P zCDQ+7;@>R$13uq10I+I40eg`xs9j?N_Dd%aSaiVR_W%I$yKlkNCzL=651DUOSSq$Ed=-((3YAKgCY2j1FI1_jrmEhm z3sv(~%T$l4UQ>OpMpZLYTc&xiMv2YpRx)mRPGut5K^*>%BIv?Wdil zy+ylO`+*KY$4Vz$Cr4+G&IO(4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ce<=TG`LXp=(5L&88IzO$1Ou4!{1CdwXaE2J24YJ`L;xTFO#slw6IeU|000Sa zNLh0L01m_e01m_fl`9S#0003nNklC9Tk#qG+h@YT?3RMROg@Q;GM8R|s9i$3^h?3CfkS0iIMMD(-aNN6h_ul>Q z-Te>#0#XuWR0t+txSu&irUY3PWJCtWsMv6vie%lm-QHIKMxLk1KiRQJF3C)Q!!S%7 zzTfzEu0=w9*ecT6jM`@`RnMu4phScPLT=ne$;xc#dQXi> z7jqkU?HYZV0cfrJjsxC)b?%r5rYWCo jU_K1P0Vt(@|3m!%m~f+rGVF@|00000NkvXXu0mjfqSUOk literal 0 HcmV?d00001 diff --git a/api-samples/tabCapture/manifest.json b/api-samples/tabCapture/manifest.json new file mode 100644 index 00000000..857c18c8 --- /dev/null +++ b/api-samples/tabCapture/manifest.json @@ -0,0 +1,13 @@ +{ + "name": "Tab Capture Example", + "description": "Capture a tab and play in a