Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running out of hardware contexts when using in iframe(s) in Chrome #34

Closed
benzimmer opened this issue Mar 1, 2016 · 6 comments
Closed
Labels

Comments

@benzimmer
Copy link

When the waveform-data.js library is loaded in multiple iframes on the same page the current tab will run out of hardware contexts to spawn new AudioContext instances. This seems to be an issue with at least Chrome (latest as of today).

embedded-page.html

<script src="https://cdn.rawgit.com/bbcrd/waveform-data.js/master/dist/waveform-data.js"></script>

embedding-page.html

<iframe src="embedded-page.html"></iframe>
<iframe src="embedded-page.html"></iframe>
<iframe src="embedded-page.html"></iframe>
<iframe src="embedded-page.html"></iframe>
<iframe src="embedded-page.html"></iframe>
<iframe src="embedded-page.html"></iframe>
<iframe src="embedded-page.html"></iframe>

Demo (open dev console): https://jsfiddle.net/r9sv6q9f/

You should see the following error in the console:

Uncaught NotSupportedError: Failed to construct 'AudioContext': The number of hardware contexts provided (6) is greater than or equal to the maximum bound (6).

The error is produced by this line: https://github.com/bbcrd/waveform-data.js/blob/master/dist/waveform-data.js#L1380

If you need further information please let me know.

@thom4parisot
Copy link
Contributor

Hello!

Well this is a limit of AudioContext per domain (see #24 which describes a similar issue in the past, for different reasons) – a singleton is in use to avoid exhausting this limit. But as you are using iframes, thus a different global space for your JavaScript code, we are likely hit this problem as you reach a certain number of iframes.

I'd rather use either a SharedWorker, recycle the iframes and/or make the iframes to communicate with their parent window to mitigate the issue.

Is it of any help?

@benzimmer
Copy link
Author

Thanks for the suggestions!

Can you tell me what the AudioContext is used for? Is it only for extracting the waveform from the audio file when there is no additional data (.json or .dat) present?

@thom4parisot
Copy link
Contributor

@benzimmer yes indeed it is used in conjunction with the Web Audio waveform generation but saying this, I feel it creates an AudioContext even if the Web Audio decoding is not used at all. Do you use it? If not, it should not really be a penalty hit on your side.

@benzimmer
Copy link
Author

No, I don't use it. My main problem here is that the AudioContext is already initialized as soon as the script is loaded and not only when the Context is actually used. But if I see correctly this comes from https://github.com/juliangruber/audio-context/blob/master/index.js#L3

@thom4parisot
Copy link
Contributor

Indeed, but it is initialised as soon as waveform-data is required, see waveform-data.js#L7.

I will scratch my head a bit to make this lazy loaded.

A way to work around this for the time being would be to do this:

const WaveformData = require('waveform-data/lib/core');
WaveformData.adapters = require('waveform-data/lib/adapters');

// ...

Another possible solution for us would be to build a version of it without the Web Audio builder, especially in case you do not have any build pipeline.

@thom4parisot
Copy link
Contributor

Hi @benzimmer,

#37, #38 andv2.0.0 changed the way AudioContext is used to generate waveform data. It is also distributed as an opt-in so you should not be annoyed anymore. The README gives (more) explainations about this – previously, it was some kind of undocumented feature, but kind of blocking in your case.

I will close this issue for now but feel free to comment on it later on, and to ask for additional support if the latest release would not really solve your issue.

Thanks for your patience :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants