@@ -3,6 +3,7 @@ import http from 'node:http';
3
3
import assert from 'node:assert/strict' ;
4
4
import puppeteer from 'puppeteer' ;
5
5
import getPort from 'get-port' ;
6
+ import { outdent } from 'outdent' ;
6
7
import { getGlobalThisProperties , createGlobals } from './utilities.mjs' ;
7
8
8
9
const ignoredGlobals = new Set ( [
@@ -134,7 +135,11 @@ async function navigateToSecureContext(page, responses) {
134
135
} ;
135
136
}
136
137
137
- async function runInBrowser ( function_ , { product, secureContext = false } = { } ) {
138
+ async function runInBrowser ( function_ , {
139
+ product,
140
+ secureContext = false ,
141
+ arguments : arguments_ = [ ] ,
142
+ } = { } ) {
138
143
await downloadBrowser ( { product} ) ;
139
144
140
145
const browser = await puppeteer . launch ( { product} ) ;
@@ -150,13 +155,47 @@ async function runInBrowser(function_, {product, secureContext = false} = {}) {
150
155
) ;
151
156
}
152
157
153
- return await page . evaluate ( function_ ) ;
158
+ return await page . evaluate ( function_ , arguments_ ) ;
154
159
} finally {
155
160
await browser . close ( ) ;
156
161
await server ?. close ( ) ;
157
162
}
158
163
}
159
164
165
+ async function runInAudioWorklet ( function_ ) {
166
+ const workletCode = outdent `
167
+ registerProcessor('execute-processor', class extends AudioWorkletProcessor {
168
+ constructor() {
169
+ super();
170
+
171
+ this.port.postMessage(${ function_ } ());
172
+ }
173
+ process() {
174
+ return true;
175
+ }
176
+ });
177
+ ` ;
178
+
179
+ return runInBrowser ( async workletCode => {
180
+ // eslint-disable-next-line no-undef -- execute in browser
181
+ const context = new AudioContext ( ) ;
182
+ const workletUrl = URL . createObjectURL ( new Blob ( [ workletCode ] , { type : 'application/javascript' } ) ) ;
183
+ await context . audioWorklet . addModule ( workletUrl ) ;
184
+ URL . revokeObjectURL ( workletUrl ) ;
185
+ return new Promise ( resolve => {
186
+ // eslint-disable-next-line no-undef -- execute in browser
187
+ const node = new AudioWorkletNode ( context , 'execute-processor' ) ;
188
+ // eslint-disable-next-line unicorn/prefer-add-event-listener -- not working
189
+ node . port . onmessage = ( { data} ) => {
190
+ resolve ( data ) ;
191
+ } ;
192
+ } ) ;
193
+ } , {
194
+ secureContext : true ,
195
+ arguments : [ workletCode ] ,
196
+ } ) ;
197
+ }
198
+
160
199
async function runInWebWorker ( function_ ) {
161
200
await downloadBrowser ( ) ;
162
201
@@ -196,11 +235,13 @@ async function runInWebWorker(function_) {
196
235
async function getBrowserGlobals ( ) {
197
236
const chromeGlobals = await runInBrowser ( getGlobalThisProperties , { secureContext : true } ) ;
198
237
const firefoxGlobals = await runInBrowser ( getGlobalThisProperties , { product : 'firefox' , secureContext : true } ) ;
238
+ const audioWorkletGlobals = await runInAudioWorklet ( getGlobalThisProperties ) ;
199
239
200
240
return createGlobals (
201
241
[
202
242
...chromeGlobals ,
203
243
...firefoxGlobals ,
244
+ ...audioWorkletGlobals ,
204
245
] ,
205
246
{
206
247
shouldExclude,
0 commit comments