Skip to content

location.href is evaluated as JavaScript code #379

vschoettke opened this Issue Jul 26, 2012 · 0 comments

2 participants


When a javascript: link executes a function that sets the location.href the new location is evaluated as JavaScript instead of loading the url

Here is a simple example:

var zombie = require('zombie');
var browser = new zombie.Browser();
browser.evaluate('function test() { location.href="/test/page.html"; }');
browser.evaluate('document.write(\'<a href="javascript:test()">Test</a>\');');

browser.error will be:
[SyntaxError: Invalid flags supplied to RegExp constructor 'page']

The cause seems to be that the url context of the executed script is not the page url but rather the url of the execution ("javascript:"). So when a script that was called via a javascript: url sets the location.href zombie.js will try to execute the content of location.href because url.protocol is still "javascript:". See 's _pageChanged and _resource functions.

@assaf assaf closed this Sep 25, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.