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

TypeError: null is not an object (evaluating 'o.ctx.createGain') #1021

Closed
nsinotov opened this issue Aug 14, 2018 · 7 comments
Closed

TypeError: null is not an object (evaluating 'o.ctx.createGain') #1021

nsinotov opened this issue Aug 14, 2018 · 7 comments

Comments

@nsinotov
Copy link

nsinotov commented Aug 14, 2018

Hey guys

I catch sometimes this issue TypeError: null is not an object (evaluating 'o.ctx.createGain')

Howler.js version: 2.0.14
iOS 11.0
Safari browser

Usage:
I call Howler.mute(false) when audio context is not created. Function mute calls setupAudioContext() in src/howler.core.js:119. The error occurs in src/howler.core.js:2309:45 when code tries to check type of Howler.ctx.createGain but ctx is null.

Please pay your attention on that

@francois-dibulo
Copy link

francois-dibulo commented Sep 7, 2018

I get a similar error (mostly on browsers like Opera on SmartTVs and Linux OS)

   Uncaught TypeError: n.ctx.createGainNode is not a function

@goldfire
Copy link
Owner

Can you provide any further steps to reproduce? I've been unable to so far and looking through the code am confused how this error could happen as it is checking for this case. Howler.usingWebAudio can only be true when the ctx has been set. I must be overlooking something, but it would be easier to figure out if I could get the error to happen.

@nemo-js
Copy link

nemo-js commented Oct 15, 2018

Same here on browsers like Opera and SmartTVs (webOS 3.0). My case is quite complicated, so I will try to simplify it and come back with a replication scenario

@francois-dibulo
Copy link

francois-dibulo commented Nov 1, 2018

Not sure how much it helps, but I now basically check if I can use Howler like this:
(and if not, I don't play sound on that device)

function canUseHowler() {
  var ctx = null;
  try {
      if (typeof AudioContext !== 'undefined') {
        ctx = new AudioContext();
      } else if (typeof webkitAudioContext !== 'undefined') {
        ctx = new webkitAudioContext();
      }
  } catch(e) {
  }

  return ctx && (ctx["createGainNode"] !== undefined || ctx["createGain"] !== undefined);
}

Some of the user-agents which had this problem:

Mozilla/5.0 (Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 OPR/22.0.1481.0 OMI/4.2.12.48.ALSAN3.56 

Mozilla/5.0 (Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.130 Safari/537.36 OPR/31.0.1890.0 OMI/4.6.1.40.Dominik2.157 VSTVB MB100 HbbTV/1.2.1 (; JVC; MB110; 2.18.2.0; ;) SmartTvA/3.0.0

Mozilla/5.0 (Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36 OPR/36.0.2128.0 OMI/4.8.0.66.Driver2.33 , _TV_MT5800/012.002.058.001 (Philips, 32PHG5102-77, wireless) CE-HTML/1.0 NETTV/4.5.0 SignOn/2.0 SmartTvA/4.0.0

Unfortunately I don't have any of this devices

@nsinotov
Copy link
Author

This error only occurs in the Safari browser for both Mac OS and iOS. We have a lot of such issues registered in Sentry but I still can not reproduce it on my Mac and iPhone. Here is the same issue #1063

@atsikov
Copy link

atsikov commented Nov 27, 2018

It looks like it usually happens when howler tries to retrieve more contexts than browser may allow (e.g., a few apps using howler are opened on the same tab in multiple iframes). Not sure about limit in Safari, but for e.g. MS Edge it's 6.

@dominiceden
Copy link

dominiceden commented Feb 7, 2020

Unrelated to this issue, but I believe Safari has a limit of 4. I've run into this with React components accidentally creating multiple AudioContext instances which seem to be fine in Firefox and Chrome, but Safari doesn't like this so when you try window.webkitAudioContext() for the 5th time it resolves to null, causing issues. The solution was to store the audio context instance in a variable.

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

No branches or pull requests

6 participants