Closed
Description
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
When attempting to use raven-js in a ServiceWorker, Raven._makeRequest
will fail because XMLHttpRequest
is not available to SW environments.
What is the expected behavior?
Use the fetch
api when available.
Which versions of Raven.js, and which browser and OS are affected by this issue?
All
Did this work in previous versions of Raven.js?
No
Are you using the CDN (http://ravenjs.com)?
No
Are you using hosted Sentry or on-premises?
Hosted
I put in a really quick hack into our /sw.js to make it work:
Raven._makeRequest = (opts) => {
const auth = Object.keys(opts.auth).map((key) => `${key}=${opts.auth[key]}`).join('&');
const headers = new Headers();
headers.append('origin', self.location.origin);
const req = new Request(`${opts.url}?${auth}`, {
method: 'POST',
body: new Blob([ JSON.stringify({ ...opts.data, ...opts.auth }, null, 2)], { type: 'application/json' }),
mode: 'cors',
credentials: 'omit',
headers,
referrer: self.location.origin
});
fetch(req);
}
Metadata
Metadata
Assignees
Labels
No labels