Search code examples
javascriptxmlxmldocumentmicrosoft-edge

Document.evaluate for documents without namespaceURI crashes Microsoft Edge


Tested on Microsoft Edge from Windows 10 build 10240. Fixed in build 10586.

Synopsis

Running XMLDocument.prototype.evaluate on a document that has namespaceURI set to null crashes the current tab process in Microsoft Edge, leaves the developer tools for that tab unresponsive, sends debug information to watson.telemetry.microsoft.com, and force-reloads the page.

Repro

To reproduce, open any website in Microsoft Edge, hit F12 to open developer tools, select Console, and run these 3 lines of javascript:

var doc = document.implementation.createDocument(null, null, null);
var node = doc.createElement('A');
doc.evaluate('B', node, doc.createNSResolver(doc), 9, null);

Solution

  • Workaround

    Access the baseURI property of the context node before running evaluate.

    var doc = document.implementation.createDocument(null, null, null);
    var node = doc.createElement('A');
    
    node.baseURI; // Edge workaround http://stackoverflow.com/q/33887400/823663
    
    doc.evaluate('B', node, doc.createNSResolver(doc), 9, null);