Skip to content

Logging DOM Document objects causes test failures (PhantomJS, Chrome) #1106

@joshdick

Description

@joshdick

I have the following basic Mocha test case that runs via Karma:

it.only("shouldn't fail when logging a DOM Document object", function() {
    var parser = new DOMParser();
    var doc = parser.parseFromString("<test></test>", "application/xml");
    console.log(doc); //Causes the test to fail
});

Running the test under PhantomJS triggers a test failure with the following error:

PhantomJS 1.9.7 (Mac OS X)  shouldn't fail when logging a DOM Document object FAILED
    Error: SECURITY_ERR: DOM Exception 18
        at stringify (http://localhost:9876/karma.js:327)
        at stringify (http://localhost:9876/karma.js:327)
        at stringify (http://localhost:9876/karma.js:327)
        at http://localhost:9876/karma.js:107
        at http://localhost:9876/karma.js:85
        ...

A similar but more informative error appears when running the same test in Chrome:

Chrome 35.0.1916 (Mac OS X 10.9.3)  shouldn't fail when logging a DOM Document object FAILED
    Error: Failed to read the 'cookie' property from 'Document': Access is denied for this document.
        at Error (native)
        at stringify (http://localhost:9876/karma.js:327:47)
        at log (http://localhost:9876/karma.js:107:24)
        at Console.localConsole.(anonymous function) [as log] (http://localhost:9876/karma.js:85:16)
        ...

I wouldn't expect doing a console.log() to cause a test failure, but it looks like Karma's internal stringify() function accesses the Document object's cookie property which the browsers don't allow, and hence causes the browsers to throw exceptions which then fail the test.

Is this correct behavior? Should Karma's stringify() function handle this better? Manually running the same code in Chrome's console shows an exception for cookie property alone but still shows the other properties in the object.

(Note: The test code as presented here was simplified, but I ran into this issue by trying to log a backone.js model that referenced a DOM Document object internally.)

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions