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

Alternative to the audio hack to disable background throttling? #7553

Closed
danburzo opened this issue Oct 11, 2016 · 2 comments
Closed

Alternative to the audio hack to disable background throttling? #7553

danburzo opened this issue Oct 11, 2016 · 2 comments
Labels
blocked/need-info ❌ Cannot proceed without more information

Comments

@danburzo
Copy link
Contributor

danburzo commented Oct 11, 2016

Electron version: 1.4.3

Hi there, we were going to use the audio hack to prevent the browser window from being throttled, but since the Electron app works on a Linode machine running Ubuntu, it throws an error about not finding any sound cards:

ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4248:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4248:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4248:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4727:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4248:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4248:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4248:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4727:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default

Installing a dummy audio card on a Linode machine seems extremely complicated (something about the Linode kernel not having the necessary features?), so I was wondering if anyone is aware of any alternative hacks to obtain the same result, without requiring a real/fake sound card.

Please note that neither webPreferences.backgroundThrottling, nor the disable-renderer-backgrounding work by themselves to prevent throttling.

Here's the mini test-case I'm using:

var app = require('electron').app;
var BrowserWindow = require('electron').BrowserWindow;

app.commandLine.appendSwitch("disable-renderer-backgrounding");

app.disableHardwareAcceleration();

var win, main, iteration = 0;

function leakke_li() {

    if (win) {
        win.destroy();
    }
    win = new BrowserWindow({
        width: 20000,
        height: 20000,
        webPreferences: {
            offscreen: true,
            backgroundThrottling: false
        },
        show: false
    });
    win.webContents.on('did-finish-load', function() {
        win.webContents.executeJavaScript(`(function(){
            // Start a silent audio source in the web page
            // to prevent it from being throttled in the background 
            // by an overzealous Chromium.
            // Reference: https://github.com/atom/atom/pull/9485/files
            var context = new AudioContext();
            var source = context.createBufferSource();
            source.connect(context.destination);
            source.start(0);
        })()`, function() {
            console.log('apply audio hack');
        });
        console.log('event:did-finish-load', ++iteration);
        win.webContents.once('paint', function(event, dirty, image) {
            console.log('event:paint');
            setTimeout(leakke_li, 300);
        });
        win.webContents.invalidate();
    });
    win.loadURL('about:blank');
}
app.on('ready', function() {
    var main = new BrowserWindow({ 
        width: 10, 
        height: 10, 
        webPreferences: {
            backgroundThrottling: false
        } 
    });
    leakke_li();
});

(It's a riff on the code in #7350)


Note for posterity: On a normal Ubuntu Server machine, getting a dummy sound card to make the Audio hack to work is as follows:

sudo apt-get install --reinstall linux-image-extra-`uname -r`
sudo modprobe snd-dummy

(With the caveat that I can provide no warranties about what it does to the machine, exercise caution. Reference)


Possible alternative?

On Mac, I've had some success with controlling the focus of the windows through window.focus() / app.focus(), but I'm not sure how focus management works with an Electron running with xvfb in a headless Ubuntu, so any pointers in this direction are much appreciated.

@zcbenz zcbenz added the blocked/need-info ❌ Cannot proceed without more information label Oct 24, 2016
@zcbenz
Copy link
Member

zcbenz commented Oct 24, 2016

Can you try whether backgroundThrottling works in 1.3.x and 1.2x? It might be a regression.

@kevinsawicki
Copy link
Contributor

Closing this out until more information is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/need-info ❌ Cannot proceed without more information
Projects
None yet
Development

No branches or pull requests

3 participants