Last active
February 24, 2022 15:04
-
-
Save Korilakkuma/e7c8af01eadfd673242b2ce7ecfd2054 to your computer and use it in GitHub Desktop.
Web Audio API Library (https://github.com/Korilakkuma/XSound) on Headless Chrome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const chrome = require('chrome-remote-interface'); | |
const ChromeLauncher = require('chrome-launcher').Launcher; | |
function launchChrome() { | |
const launcher = new ChromeLauncher(); | |
return Promise.resolve(launcher); | |
} | |
function onPageLoad(Runtime) { | |
// https://github.com/Korilakkuma/XSound | |
const js = ` | |
X('oscillator').setup(true); | |
X('oscillator').get(0).param('type', 'sawtooth'); | |
X('oscillator').ready().start(440); | |
`; | |
return Promise.resolve(Runtime.evaluate({ expression : js })); | |
} | |
launchChrome().then(launcher => { | |
chrome(protocol => { | |
const { Page, Runtime } = protocol; | |
Page.enable(); | |
Page.navigate({ url : 'https://korilakkuma.github.io/XSound/' }); | |
onPageLoad(Runtime).then(() => { | |
protocol.close(); | |
launcher.kill(); | |
}); | |
}).on('error', error => { | |
throw Error(error); | |
}); | |
}); |
Author
Korilakkuma
commented
Dec 17, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment