Issue with displaying Wavesurfer.js waveform in custom Shopify section

Greetings to the Stockoverflow Community,

I am facing a challenge with integrating WaveSurfer.js into a customized section on my Shopify store. Even though I have successfully implemented the section, the waveform visualization is not appearing.

Link to the test page:

Description of the Problem: The WaveSurfer.js library is intended to generate visual audio waveforms on the provided page, but while the audio files can be played, the waveform remains invisible. The console logs indicate that WaveSurfer is ready and there are no direct errors pointing to WaveSurfer.js itself. However, there are repeated notifications about third-party cookies being blocked, although it's uncertain if this is related.

Below is the Liquid/JavaScript snippet where WaveSurfer is initialized and expected to load and display waveforms:

(WaveSurfer.js is loaded via my theme.liquid. It was also previously loaded in the section liquid itself with

<script src="https://unpkg.com/wavesurfer.js"></script>
)

liquidCopy code
<!-- WaveSurfer Initialization -->
<script>
document.addEventListener('DOMContentLoaded', function() {
    var players = {};

    {% for block in section.blocks %}
        players['{{ block.id }}'] = WaveSurfer.create({
            container: '#wave-{{ block.id }}',
            waveColor: '#4F4A85',
            progressColor: '#383351',
            cursorColor: 'transparent',
            barWidth: 2,
            height: 60,
            responsive: true,
            autoCenter: true
        });

        players['{{ block.id }}'].load('{{ block.settings.audio_url }}');

        players['{{ block.id }}'].on('ready', function() {
            console.log('WaveSurfer is ready for block ' + '{{ block.id }}');
        });

        players['{{ block.id }}'].on('error', function(e) {
            console.error('WaveSurfer error:', e);
        });
    {% endfor %}

    window.togglePlay = function(blockId) {
        var player = players[blockId];
        if (player) {
            player.playPause();
        }
    };
});
</script>

I would greatly appreciate any guidance or recommendations to address this issue, especially if anyone has encountered similar difficulties with WaveSurfer.js or has insights on how warnings about third-party cookies may affect JavaScript functionality.

Thank you in advance for your assistance!

Ensured that the wavesurfer.min.js script is correctly loaded in the site's theme files and globally accessible. Confirmed that the initialization script for WaveSurfer is appropriately connected to each audio block and verified that it executes after the DOM is fully loaded. Verified that there are no visible browser console errors directly linked to the operation of WaveSurfer. Tested in multiple browsers to eliminate any browser-specific issues.

Answer №1

Your base.css file contains the following rule:

a:empty,
ul:empty,
dl:empty,
div:empty,
section:empty,
article:empty,
p:empty,
h1:empty,
h2:empty,
h3:empty,
h4:empty,
h5:empty,
h6:empty {
  display: none;
}

This rule is causing a conflict with WaveSurfer's rendering, as mentioned in this comment

An easy solution would be to add the following CSS rule:

.waveform div:empty {
  display: block;
}

https://i.sstatic.net/jlSvd.png

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

Exploring the Differences: innerHTML versus appendChild for Loading Scripts

Struggling to dynamically load scripts onto the DOM? function addScript(fileName) { document.body.innerHTML += `<script src='components/${fileName}/${fileName}.js'></script>` } addScript('message-interface') I prefer th ...

Dnd-kit: item loses its place in line when dragged over Droppable area

I've encountered an issue while using @dnd-kit. The sorting function works smoothly (e.g. when I drag the 1st element, it sorts correctly), but once I reach a droppable element (green Thrash), the sorting breaks and the 1st element snaps back. You ca ...

The removeEventListener function is failing to properly remove the keydown event

Every time my component is rendered, I attach an event listener. mounted() { window.addEventListener("keydown", e => this.moveIndex(e)); } Interestingly, even when placed within the moveIndex method itself, the event listener persists and cannot ...

JavaScript Event Listener not Working Properly

I've been attempting to implement a feature on my website where the header hides when scrolling down and re-appears when scrolling up. However, I'm struggling to make use of the code snippet below to achieve this functionality. Despite my thoroug ...

Ways to control the quantity of ajax POST requests?

Currently, I am utilizing angular (in case it makes a difference) and endeavoring to restrict the quantity of ajax POST requests that my browser sends using javascript - particularly interested in vanilla javascript on the xmlHttpRequest object. Any insigh ...

CSS code for vertical navigation arrows to remain on both the left and right sides of the webpage

I'm struggling a bit with the CSS. I want to recreate the same effect as seen on . The left and right navigation arrows stay fixed vertically even when scrolling up or down the page. Does anyone have any code examples for that? ...

Increase the totalAmount by adding the product each time

Can someone help me understand why the totalAmount shows as 20 when I add a product? Also, why doesn't it increase when I try to increment it? Any insights would be appreciated. Thank you. ts.file productList = [ { id: 1, name: 'Louis ...

Enhance your browsing experience by inputting valuable information into the

I am looking to enhance a text box by adding values. The text box already has a default value of 10, and I want to create a button that will add new text boxes with a limit of 4. My goal is to continuously add values from text box 1 to text box 4. For exa ...

Whenever I am building a React application, I encounter a bug that states: "node:fs:1380 const result = binding.mkdir()"

Whenever I try to enter the command: create-react-app my-app --template typescript I keep encountering this error message: node:fs:1380 const result = binding.mkdir( ^ Error: EPERM: operation not permitted, mkdir 'D:\ ...

Is it necessary to specify a data type for the response when making an AJAX POST request?

After carefully reviewing my code, I have ensured that all the variables in my JavaScript match and are properly set up. Additionally, I have confirmed that all the variables in my data array for my AJAX request correspond correctly to my $_POST['var& ...

Is it possible to load HTML content within a Sweet Alert pop-up

Below is the code I am using to call Swal: window.swal({ title: "Checking...", text: "Please wait", imageUrl: "{{ asset('media/photos/loaderspin.gif') }}", showConfirmButton: false, allowOutsideClick: false }); $.ajax({ t ...

What is the process for performing the "extract function" refactoring in JavaScript?

Are there any tools for extracting functions in JavaScript similar to the "extract function" refactoring feature available for Java and jQuery developers in Eclipse or Aptana? Or perhaps in another JavaScript/jQuery IDE? ...

Tips on implementing two ng-repeat directives within a specific element

Inside a JSON file, there is an array that needs to be iterated within <td> tags. The functionality entails creating a table based on user input, which includes the number of rows, input columns, and output columns provided by the user. Three arrays ...

How to handle event methods with Vue

Currently, I am facing a challenge in passing an event downward with a bound change listener to a child input component. Although I am utilizing wrapped input components, my goal is to define methods within the parent component. //App.js: <currency-inp ...

Is it possible to integrate two calendars into the `DatePicker` component of MUI?

The <DateRangePicker/> component from MUI has a prop called calendars which determines the number of calendars displayed inside the component popup. Here is an example: If the calendars prop has a value of "3", it will look like this: https://i.sta ...

The height of the div element is automatically adjusted to zero

I am dealing with a simple layout where I have a main div that floats to the left. Within this main div, I nest other divs using the clear both style. Below is a simplified version of my setup: <div id="wrapper" class="floatLeft"> <div id="ma ...

AngularJS application failing to initialize without a module being included

I'm feeling a bit lost when it comes to angularjs and I have a question about why my angularjs app is refusing to bootstrap without creating a module, even though egghead.io and other tutorials seem to suggest otherwise. Here's a snippet of my HT ...

I encountered a permission denied error while attempting to execute the command npm install -g tsc

My main objective is to convert TypeScript code to JavaScript. However, when I attempted to install the TypeScript compiler globally using 'npm install -g tsc', I encountered the following error: npm ERR! Error: EACCES: permission denied, rename ...

AngularJS does not recognize Model as a date object in the input

I am attempting to utilize AngularJS to showcase a date using an input tag with the type attribute set to date: <input ng-model="campaign.date_start" type="date"> Unfortunately, this approach is resulting in the following error message: Error: err ...

JavaScript - Utilizing jQuery to dynamically add and remove input fields

I have a form where input fields (groups) are added dynamically. Here's a glimpse of the complex form: FIDDLE The error on the console reads: Error: uncaught exception: query function not defined for Select2 s2id_autogen1 With existing fields in t ...