1
- import {
2
- getCurrentTab ,
3
- runScriptInTab ,
4
- waitForTabToLoad ,
5
- } from "./helpers/utils.js" ;
1
+ import { runScriptInTab , waitForTabToLoad } from "./helpers/utils.js" ;
6
2
7
3
export default {
8
4
icon : "" ,
@@ -25,105 +21,24 @@ export default {
25
21
// https://stackoverflow.com/questions/66217882/properly-using-chrome-tabcapture-in-a-manifest-v3-extension
26
22
// https://groups.google.com/a/chromium.org/g/chromium-extensions/c/ffI0iNd79oo
27
23
// https://github.dev/GoogleChrome/chrome-extensions-samples/api-samples/tabCapture
28
-
29
- onClick : async ( ) => {
30
- // https://developer.chrome.com/docs/extensions/how-to/web-platform/screen-capture
31
- const stream = await navigator . mediaDevices . getDisplayMedia ( {
32
- video : {
33
- displaySurface : "browser" ,
34
- } ,
35
- audio : {
36
- suppressLocalAudioPlayback : false ,
37
- } ,
38
- preferCurrentTab : false ,
39
- selfBrowserSurface : "exclude" ,
40
- systemAudio : "include" ,
41
- surfaceSwitching : "include" ,
42
- monitorTypeSurfaces : "include" ,
24
+ // https://developer.chrome.com/docs/extensions/how-to/web-platform/screen-capture
25
+
26
+ onClickExtension : async ( ) => {
27
+ const { tabs } = await chrome . windows . create ( {
28
+ url : "http://127.0.0.1:5500/public/music-visualizer/index.html" ,
29
+ type : "popup" ,
30
+ width : 800 ,
31
+ height : 300 ,
43
32
} ) ;
33
+ const tab = tabs [ 0 ] ;
44
34
45
- drawVisualizer ( stream ) ;
46
-
47
- // const streamId = await UfsGlobal.Extension.runInBackground(
48
- // "chrome.tabCapture.getMediaStreamId"
49
- // );
50
- // navigator.webkitGetUserMedia(
51
- // {
52
- // audio: {
53
- // mandatory: {
54
- // chromeMediaSource: "tab", // The media source must be 'tab' here.
55
- // chromeMediaSourceId: streamId,
56
- // },
57
- // },
58
- // video: false,
59
- // },
60
- // function (stream) {
61
- // console.log(stream);
62
- // },
63
- // function (error) {
64
- // console.error(error);
65
- // }
66
- // );
67
- } ,
68
-
69
- _onClickExtension : async ( ) => {
70
- try {
71
- // const url = "http://127.0.0.1:5500/public/music-visualizer/index.html";
72
- const url = await chrome . runtime . getURL (
73
- "/public/music-visualizer/index.html"
74
- ) ;
75
- const currentTab = await getCurrentTab ( ) ;
76
- const newTab = await chrome . tabs . create ( {
77
- url : url ,
78
- active : false ,
79
- } ) ;
80
- await waitForTabToLoad ( newTab . id ) ;
81
-
82
- const streamId = await chrome . tabCapture . getMediaStreamId ( {
83
- targetTabId : currentTab . id ,
84
- consumerTabId : newTab . id ,
85
- } ) ;
86
-
87
- chrome . tabs . update ( newTab . id , {
88
- url : url + "?streamId=" + streamId ,
89
- } ) ;
35
+ await waitForTabToLoad ( tab . id ) ;
90
36
91
- // runScriptInTab({
92
- // tabId: newTab.id,
93
- // func: (streamId) => {
94
- // start(streamId);
95
- // },
96
- // args: [streamId],
97
- // });
98
- } catch ( e ) {
99
- alert ( e ) ;
100
- }
101
- } ,
102
-
103
- _onClickContentScript : async ( ) => {
104
- try {
105
- const currentTabId = await UfsGlobal . Extension . runInBackground (
106
- "utils.getCurrentTabId"
107
- ) ;
108
-
109
- const url = await UfsGlobal . Extension . getURL ( "/scripts/_test.html" ) ;
110
- const { tabs } = await UfsGlobal . Extension . runInBackground (
111
- "chrome.windows.create" ,
112
- [ { url, height : 400 , width : 800 } ]
113
- ) ;
114
- const tab = tabs [ 0 ] ;
115
-
116
- await UfsGlobal . Extension . waitForTabToLoad ( tab . id ) ;
117
-
118
- UfsGlobal . Extension . runInBackground ( "chrome.tabs.sendMessage" , [
119
- tab . id ,
120
- {
121
- targetTabId : currentTabId ,
122
- consumerTabId : tab . id ,
123
- } ,
124
- ] ) ;
125
- } catch ( e ) {
126
- console . log ( e ) ;
127
- }
37
+ runScriptInTab ( {
38
+ func : ( ) => {
39
+ window . ufs_call_init ?. ( ) ;
40
+ } ,
41
+ tabId : tab . id ,
42
+ } ) ;
128
43
} ,
129
44
} ;
0 commit comments