question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

XHR headers not sent, misspelled headers options in util.fetchFile

See original GitHub issue

Wavesurfer.js version(s): 4.0.1 Browser and operating system version(s): Firefox, Ubuntu 20.04 Code needed to reproduce the issue:

this.wave = WaveSurfer.create({
    container: '#waveform',
    waveColor: '#3f51b5',
    progressColor: 'blue',
    xhr: {
        [{ key: 'Authorization', value: 'Bearer token' }]
    }
});

No header sent in request. Checked the code and getArrayBuffer function calls util.fetchFile with options containing params.xhr ( containings headers )

    getArrayBuffer(url, callback) {
        let options = Object.assign(
            {
                url: url,
                responseType: 'arraybuffer'
            },
            this.params.xhr
        );
        const request = util.fetchFile(options);
        ...
    }

when checking util.fetchFile i see it looks for options.requestHeaders, instead of options.headers i think.



    // check if headers have to be added
    if (options && options.requestHeaders) {
        // add custom request headers
        options.requestHeaders.forEach(header => {
            fetchHeaders.append(header.key, header.value);
        });
    }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
codinboxcommented, Jul 30, 2020

Not a bug but a doc mistake. as you said the right option to use is xhr: { requestHeaders: {} } and not xhr: { headers: {} } I changed it in my code and now my keys are sent.

0reactions
flaffcommented, Jul 30, 2020

Maybe a good idea to update the doc to.

Where is the doc error visible?

Documentation > Options > xhr

XHR options. For example: let xhr = { cache: ‘default’, mode: ‘cors’, method: ‘GET’, credentials: ‘same-origin’, redirect: ‘follow’, referrer: ‘client’, headers: [ { key: ‘Authorization’, value: ‘my-token’ } ]};

Read more comments on GitHub >

github_iconTop Results From Across the Web

`xhr.getAllHeaders()` is missing some headers in a browser ...
I am working on a browser extension. In a script running on the popup page, I am making an ajax request. On the...
Read more >
List of HTTP header fields - Wikipedia
HTTP header fields are a list of strings sent and received by both the client program and server on every HTTP request and...
Read more >
That's so fetch! - JakeArchibald.com
This is because it's a CORS request and the response doesn't have CORS headers. However, with fetch, you can make a no-cors request:....
Read more >
XMLHttpRequest Standard
During this state request headers can be set using setRequestHeader() and the fetch can be initiated using the send() method. headers received ...
Read more >
Using Fetch | CSS-Tricks
Ajax is a technique to send and retrieve information. ... The second option is to set your headers. Since we're primarily sending JSON...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found