diff --git a/package.json b/package.json index 5f55937..ad4af0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@webrecorder/wombat", - "version": "3.3.4", + "version": "3.3.5", "main": "index.js", "license": "AGPL-3.0-or-later", "author": "Ilya Kreymer, Webrecorder Software", diff --git a/src/wombat.js b/src/wombat.js index 39bfb24..418c2bb 100755 --- a/src/wombat.js +++ b/src/wombat.js @@ -5123,8 +5123,18 @@ Wombat.prototype.initProtoPmOrigin = function(win) { }); } catch (e) {} - win.__WB_check_loc = function(loc) { + win.__WB_check_loc = function(loc, args) { if (loc instanceof Location || loc instanceof WombatLocation) { + // args, if provided, should be the 'arguments' from calling function + // check if the location is actually a locally passed in argument, + // if so, don't assign to global location + if (args) { + for (var i = 0; i < args.length; i++) { + if (loc === args[i]) { + return {}; + } + } + } return this.WB_wombat_location; } else { return {}; diff --git a/test/overrides-browser.js b/test/overrides-browser.js index b5fccef..755a843 100644 --- a/test/overrides-browser.js +++ b/test/overrides-browser.js @@ -139,6 +139,25 @@ test('WombatLocation: should have a Symbol.toStringTag value of "Location"', asy ); }); +test('WombatLocation should not navigate when assigning to local object', async t => { + const { sandbox, server } = t.context; + const result = await sandbox.evaluate(() => { + let location = window.WB_wombat_location; + + function navTest(location) { + location = ((self.__WB_check_loc && self.__WB_check_loc(location, arguments)) || {}).href = location.protocol + '//' + location.hostname + '/it'; + return location; + } + + return navTest(location); + }); + t.is( + result, + 'https://tests.wombat.io/it', + 'the page navigated away and did not return a URL' + ); +}); + test('WombatLocation browser navigation control: should rewrite Location.replace usage', async t => { const { sandbox, server } = t.context; const [navigationResponse] = await Promise.all([