When the inspector is open, Chrome freezes when multiple addModule() calls are made on the audioCtx

I am currently focused on developing a method to load AudioWorklet processors using OfflineAudioContext objects. My goal is to pre-generate and present visual data related to sounds that will eventually be played for the user.

My approach involves utilizing an OfflineAudioContext, with the intention of writing processor.js to store the generated audio, though this phase is still in progress.

Currently, I am working in Chrome and have not yet discovered a way to use AudioContext with Firefox or Safari browsers.

// within Sound object #1
const offlineCtx1 = new OfflineAudioContext(2, 44100, 44100);
offlineCtx1.audioWorklet.addModule("processor.js")
     .then(() => log("first context loaded the processor"));

// ...
// within Sound object #2
const offlineCtx2 = new OfflineAudioContext(2, 44100, 44100);
offlineCtx2.audioWorklet.addModule("processor.js")
    .then(() => log("second context loaded the processor"));

An issue arises when attempting to add the module to two different contexts. If the inspector is closed, the page loads smoothly. However, if the inspector is open, the browser tab freezes to some extent. Interaction with the page becomes impossible, although limited actions can be performed within the inspector.

This seems to be a timing issue: waiting for 1000ms or initiating the second addModule() call through user interaction resolves the problem effectively.

One workaround I have found is to create a promise chain from the .addModule() call, ensuring that one is completed before the next begins.

To avoid simultaneous module addition by separate audio context objects, an elaborate process of weaving Promises through objects is necessary. While the code may appear simple in isolation, managing multiple audio context modules in an application requires intricate coordination:

const offlineCtx1 = new OfflineAudioContext(2, 44100, 44100);
offlineCtx1.audioWorklet.addModule("processor.js")
    .then(() => log("first context loaded the processor") )
    .then(() => {
        const offlineCtx2 = new OfflineAudioContext(2, 44100, 44100);
        return offlineCtx2.audioWorklet.addModule("processor.js")
    })
    .then(() => log("second context loaded the processor") );

The necessity of sequential execution suggests a timing-related issue. I am running Chrome v69.0.3497.100 (Official Build) (64-bit).

If anyone has insights into why this behavior occurs or suggestions for further debugging, it would be greatly appreciated. Unfortunately, the Chrome Inspector does not provide significant information once the freezing occurs.

Examples:

  • Promise chain -- should not freeze Chrome
  • No promise chain -- might cause Chrome tab to freeze, especially with the inspector open

Answer №1

Update (10/18/2018): The latest version has resolved the issue mentioned here with bug number 891025. More information can be found in the issue entry.

It appears to be a bug, and I have reported it through crbug.com for further investigation. This particular issue involves Web Audio, Worker, and DevTools, so isolating the problem might take some time.

In the meantime, consider using async/await instead of promise chains for better code readability in this scenario.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for transferring a JavaScript variable to a Java servlet?

I am trying to send a JavaScript variable to a Java servlet in a web application I am developing. Below is the HTML code: <p id="test">Some text</p> Here is the JavaScript code I am using: var myVar = document.getElementById('test' ...

Using jQuery to enable scrolling and dynamically changing classes

I'm currently working on enhancing my website with a feature that changes the opacity of the first section to 0.4 when a user scrolls more than 400 pixels down the page. I attempted the following code without success: if($("html, body").offset().top ...

Why is it necessary to use 'then' on the response JSON when using the Fetch API? It's like trying to decipher the hidden meaning

While delving into the realm of promises, I decided to test it out with a basic GET request on Twitch. Yet, one aspect is still puzzling me - why does json() return a promise? The response already contains the data, so what's the deal with it being wr ...

Tips for effectively making REST requests from a ReactJS + Redux application?

I'm currently working on a project using ReactJS and Redux, incorporating Express and Webpack as well. I have successfully set up an API and now need to figure out how to perform CRUD operations (GET, POST, PUT, DELETE) from the client-side. Could so ...

Change the classes of the body prior to the initial rendering

I know this may seem like a difficult task, and I understand that what I want to achieve might be nearly impossible. My goal is to incorporate a dark/light mode switch on my website. The challenge lies in the fact that the site consists of static files on ...

Creating a Comprehensive Page Design with Bootstrap and the Latest Version of Vue

My goal is to develop a Single Page Application using Vue3 and the Bootstrap 5 framework with a simple layout of Header -> Content -> Footer. I want the Content section to fill the space between the header and footer, ensuring there is no overlap. Ho ...

Creating a hierarchical tree in JavaScript and generating nested UL/LI output with ExpressJS

I have a piece of code from another request that is functioning properly. It creates a hierarchical tree with deep levels using JSON. However, I require the output to be in the form of an HTML UL/LI nested structure or a select menu for parent and child el ...

Characteristics of events within the embed element

<div id='aplayer'></div> js $('#note').click(function() { $('#aplayer').html("<embed src=" + music + " onended='test();'" + ">"); }); function test(){ alert ('525'); } audio is ...

JavaScript's prime sleep function

I am in need of a sleep function for my JavaScript code. I could use a promise-based function, but it requires the await keyword to function correctly. The issue is that I need to use the sleep function at the top level of my code. function sleep(milliseco ...

Error: Trying to access the 'previous' property of an undefined value

I keep encountering an error with functions in firebase: TypeError: Cannot read property 'previous' of undefined at exports.sendNotifications.functions.database.ref.onWrite (/srv/index.js:5:19) at cloudFunction (/srv/node_modules/firebase-functi ...

Avoid displaying identical items when rendering a page from JSON data

I am using ajax and json to render a page. The structure of my json is as follows: {"status":"ok","rewards":[{"id":201,"points":500},{"id":202,"points":500}]}. I want to load the data using ajax only once if 'points' have duplicates in any of the ...

What steps can I take to refactor a portion of the component using React hooks?

I am trying to rewrite the life cycle methods in hooks but I am facing some issues. It seems like the component is not behaving as expected. How can I correct this? Can you provide guidance on how to properly rewrite it? useEffect(() => { updateUs ...

VueJS: Even when disabled, clicking a button can still navigate to a different

Is there a way to prevent the button from being clickable when the current page is the first page? Although the button disables as expected, I'm still encountering an issue where the route changes when it's clicked. Code Snippet (Javascript) ...

Guide on generating a route using coordinates in a threejs environment

Currently, I am working with an array of coordinates obtained from the Google Maps Navigation API. I have successfully plotted these coordinates on a sphere, however, my objective is to extract the shape of the path by combining all the coordinate points ...

Transform ternary conditional operators into if-else statements

I encountered an issue while attempting to convert a simple minified jQuery code to an if else statement. The error message "Can't find variable: i" is displayed. Check out the original code below: var c = slider.activeIndex; 0 === c ? (slider.slid ...

Do you have any recommendations to help me achieve the sticky footer hack?

Check out this awesome website: I've been working on incorporating a responsive design with a sticky footer, but I encountered some issues with incompatible CSS options. The fixed option wasn't meeting my needs either. For the homepage, I have ...

Beginner in html, css, and javascript: "Tips for saving jsfiddle demos?"

Recently, I developed an interest in JavaScript and CSS and came across some impressive examples on jsfiddle. I was wondering if there is a way to "export" these examples to my computer. Simply copying and pasting doesn't seem to work. How can I modi ...

Prolong the duration of a Facebook SDK access token to 60 days using C#!

How can I extend the 2-hour access token to a 60-day access token using the C# SDK? Can someone provide a sample code snippet for this specific section where the code has already been substituted with the 2-hour access token? Background: Despite trying va ...

JavaScript text converter using split() method

I have a large amount of data in text format, similar to the following: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7e0b0d1b0c1b131f17124f3e19131f1712501d1113">[email protected]</a>:token1 | Time = US | Alphabe ...

Utilizing the scrollTop method to display the number of pixels scrolled on

My goal is to show the number of pixels a user has scrolled on my website using the scrollTop method in jQuery. I want this number of pixels to be displayed within a 'pixels' class. Therefore, I plan to have <p><span class="pixels"> ...