1
- import { getCurrentTabId } from "./helpers/utils.js" ;
2
-
3
1
export default {
4
2
icon : "" ,
5
3
name : {
@@ -11,40 +9,89 @@ export default {
11
9
vi : "" ,
12
10
} ,
13
11
14
- // whiteList: [" https://www.google.com/*"],
12
+ // https://github.dev/GoogleChrome/chrome-extensions-samples/api-samples/tabCapture
15
13
16
14
onClickContentScript : async ( ) => {
15
+ try {
16
+ const tab = await UfsGlobal . Extension . runInBackground (
17
+ "utils.getCurrentTab"
18
+ ) ;
19
+
20
+ const streamId = await UfsGlobal . Extension . runInBackground (
21
+ "chrome.desktopCapture.chooseDesktopMedia" ,
22
+ [ [ "tab" , "audio" ] , tab , "callback" ]
23
+ ) ;
24
+
25
+ navigator . webkitGetUserMedia (
26
+ {
27
+ audio : {
28
+ mandatory : {
29
+ chromeMediaSource : "tab" ,
30
+ chromeMediaSourceId : streamId ,
31
+ } ,
32
+ } ,
33
+ } ,
34
+ function ( stream ) {
35
+ const context = new AudioContext ( ) ;
36
+ const source = context . createMediaStreamSource ( stream ) ;
37
+ const analyser = context . createAnalyser ( ) ;
38
+ source . connect ( analyser ) ;
39
+ source . connect ( context . destination ) ;
40
+ analyser . connect ( context . destination ) ;
41
+ } ,
42
+ function ( error ) {
43
+ alert ( "no" ) ;
44
+ console . log ( error ) ;
45
+ }
46
+ ) ;
47
+ } catch ( e ) {
48
+ console . log ( e ) ;
49
+ }
50
+ } ,
51
+
52
+ _onClickContentScript : async ( ) => {
17
53
// https://developer.chrome.com/docs/extensions/reference/api/tabCapture#preserving-system-audio
18
54
// https://github.com/Douile/Chrome-Audio-Visualizer/tree/master
55
+ // https://stackoverflow.com/questions/66217882/properly-using-chrome-tabcapture-in-a-manifest-v3-extension
56
+ // https://groups.google.com/a/chromium.org/g/chromium-extensions/c/ffI0iNd79oo
19
57
20
58
try {
21
- const currentTab = await UfsGlobal . Extension . runInBackground (
22
- "utils.getCurrentTabId "
59
+ const tab = await UfsGlobal . Extension . runInBackground (
60
+ "utils.getCurrentTab "
23
61
) ;
24
62
25
63
const streamId = await UfsGlobal . Extension . runInBackground (
26
64
"chrome.tabCapture.getMediaStreamId" ,
27
65
[
28
66
{
29
- consumerTabId : currentTab ,
30
- targetTabId : currentTab ,
67
+ targetTabId : tab . id ,
68
+ consumerTabId : tab . id ,
31
69
} ,
32
70
]
33
71
) ;
34
72
35
- const stream = await navigator . mediaDevices . getUserMedia ( {
36
- audio : {
37
- mandatory : {
38
- chromeMediaSource : "tab" ,
39
- chromeMediaSourceId : streamId ,
73
+ navigator . webkitGetUserMedia (
74
+ {
75
+ audio : {
76
+ mandatory : {
77
+ chromeMediaSource : "tab" ,
78
+ chromeMediaSourceId : streamId ,
79
+ } ,
40
80
} ,
41
81
} ,
42
- } ) ;
43
-
44
- const output = new AudioContext ( ) ;
45
- const source = output . createMediaStreamSource ( stream ) ;
46
- source . connect ( output . destination ) ;
47
- console . log ( output ) ;
82
+ function ( stream ) {
83
+ const context = new AudioContext ( ) ;
84
+ const source = context . createMediaStreamSource ( stream ) ;
85
+ const analyser = context . createAnalyser ( ) ;
86
+ source . connect ( analyser ) ;
87
+ source . connect ( context . destination ) ;
88
+ analyser . connect ( context . destination ) ;
89
+ } ,
90
+ function ( error ) {
91
+ alert ( "no" ) ;
92
+ console . log ( error ) ;
93
+ }
94
+ ) ;
48
95
} catch ( e ) {
49
96
alert ( e ) ;
50
97
}
0 commit comments