This is somewhat a duplicate of this question, but I do not understand on how to use the accepted answer. Furthermore the question is quite old and maybe there is a better way available now.
My use case:
I want to test if audio in general is playing with Playwright. The audio source is not a DOM-Element, so checking media elements is not a solution.
This is how the code would get used:
const isAudioPlaying = page.evaluate(() => {
/* Code goes here */
})
Edit: And this is how the code of the media playback looks like in its most simple form:
function createAudioPlayer() {
const audio = new Audio()
return {
setSource: (src) => audio.src = src,
play: () => audio.play,
pause: () => audio.pause,
resume: () => audio.resume,
}
}
This factory just uses the default Audio constructor for the playback. It never touches the DOM like that.