Skip to content

Commit

Permalink
feat(browser): support fetchParameters (#2567)
Browse files Browse the repository at this point in the history
Co-authored-by: Phillip Kuang <>
  • Loading branch information
kuangp committed Jun 4, 2020
1 parent dcab5ef commit 4e552ec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/browser/src/transports/fetch.ts
Expand Up @@ -35,6 +35,10 @@ export class FetchTransport extends BaseTransport {
referrerPolicy: (supportsReferrerPolicy() ? 'origin' : '') as ReferrerPolicy,
};

if (this.options.fetchParameters !== undefined) {
Object.assign(options, this.options.fetchParameters);
}

if (this.options.headers !== undefined) {
options.headers = this.options.headers;
}
Expand Down
24 changes: 24 additions & 0 deletions packages/browser/test/unit/transports/fetch.test.ts
Expand Up @@ -156,5 +156,29 @@ describe('FetchTransport', () => {
}),
).equal(true);
});

it('passes in fetch parameters', async () => {
transport = new Transports.FetchTransport({
dsn: testDsn,
fetchParameters: {
credentials: 'include',
},
});
const response = { status: 200 };

fetch.returns(Promise.resolve(response));

const res = await transport.sendEvent(payload);

expect(res.status).equal(Status.Success);
expect(
fetch.calledWith(transportUrl, {
body: JSON.stringify(payload),
credentials: 'include',
method: 'POST',
referrerPolicy: 'origin',
}),
).equal(true);
});
});
});
2 changes: 2 additions & 0 deletions packages/types/src/transport.ts
Expand Up @@ -34,4 +34,6 @@ export interface TransportOptions {
httpsProxy?: string;
/** HTTPS proxy certificates path */
caCerts?: string;
/** Fetch API init parameters */
fetchParameters?: { [key: string]: string };
}

0 comments on commit 4e552ec

Please sign in to comment.