diff --git a/src/raven.js b/src/raven.js index a111cbdeaaf0..5f79ebcb0ac9 100644 --- a/src/raven.js +++ b/src/raven.js @@ -1179,11 +1179,13 @@ Raven.prototype = { if (typeof fetchInput === 'string') { url = fetchInput; - } else { + } else if ('Request' in _window && fetchInput instanceof _window.Request) { url = fetchInput.url; if (fetchInput.method) { method = fetchInput.method; } + } else { + url = '' + fetchInput; } if (args[1] && args[1].method) { diff --git a/test/integration/test.js b/test/integration/test.js index 429121d11f00..e9601203ead0 100644 --- a/test/integration/test.js +++ b/test/integration/test.js @@ -812,6 +812,56 @@ describe('integration', function() { ); }); + it('should record a fetch request with an arbitrary type argument', function(done) { + var iframe = this.iframe; + + iframeExecute( + iframe, + done, + function() { + // some browsers trigger onpopstate for load / reset breadcrumb state + Raven._breadcrumbs = []; + + fetch(123).then( + function() { + setTimeout(done); + }, + function() { + setTimeout(done); + } + ); + }, + function() { + var Raven = iframe.contentWindow.Raven, + breadcrumbs = Raven._breadcrumbs, + breadcrumbUrl = '123'; + + if ('fetch' in window) { + assert.equal(breadcrumbs.length, 1); + + assert.equal(breadcrumbs[0].type, 'http'); + assert.equal(breadcrumbs[0].category, 'fetch'); + assert.equal(breadcrumbs[0].data.method, 'GET'); + // Request constructor normalizes the url + assert.ok(breadcrumbs[0].data.url.indexOf(breadcrumbUrl) !== -1); + } else { + // otherwise we use a fetch polyfill based on xhr + assert.equal(breadcrumbs.length, 2); + + assert.equal(breadcrumbs[0].type, 'http'); + assert.equal(breadcrumbs[0].category, 'fetch'); + assert.equal(breadcrumbs[0].data.method, 'GET'); + assert.ok(breadcrumbs[0].data.url.indexOf(breadcrumbUrl) !== -1); + + assert.equal(breadcrumbs[1].type, 'http'); + assert.equal(breadcrumbs[1].category, 'xhr'); + assert.equal(breadcrumbs[1].data.method, 'GET'); + assert.ok(breadcrumbs[1].data.url.indexOf(breadcrumbUrl) !== -1); + } + } + ); + }); + it('should record a mouse click on element WITH click handler present', function( done ) {