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

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

Closed
codinbox opened this issue Jul 26, 2020 · 8 comments
Closed

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

codinbox opened this issue Jul 26, 2020 · 8 comments

Comments

@codinbox
Copy link

codinbox commented Jul 26, 2020

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);
        });
    }
@codinbox codinbox changed the title Misspelled headers options in util.fetchFile XHR headers not sent, misspelled headers options in util.fetchFile Jul 26, 2020
@thijstriemstra
Copy link
Contributor

You should be using the requestHeaders property of the xhr object, not headers.

@flaff
Copy link

flaff commented Jul 30, 2020

The request property is a mistake in documentation - by checking typings and source code I came into conclusion it should be requestHeaders instead.

Unfortunately I can confirm requestHeaders are not working either.
It is caused by headers being empty on fetchRequest. When debugging I tried

fetchRequest.headers = fetchOptions.headers;

and it worked like charm 👍

It means that if we are providing a Request object as a first fetch argument it is expected to have headers defined on Request.

@thijstriemstra
Copy link
Contributor

hmm, so it's a bug?

@codinbox
Copy link
Author

codinbox commented 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.

@codinbox
Copy link
Author

Maybe a good idea to update the doc to.

@flaff
Copy link

flaff commented Jul 30, 2020

If it is working for you I will check other browsers, as it is not working for me on Chrome 86 (Dev).
Edit: it was a mistake on my side as I didn't notice no-cors option. Thanks 👍

@thijstriemstra
Copy link
Contributor

Maybe a good idea to update the doc to.

Where is the doc error visible?

@flaff
Copy link

flaff commented 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' } ]};

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

Successfully merging a pull request may close this issue.

3 participants