catching the jQuery parseXML exception #11208

Open
repinel opened this Issue Apr 4, 2013 · 6 comments

Comments

Projects
None yet
4 participants
@repinel

repinel commented Apr 4, 2013

I'm not sure if it's an issue, but shouldn't the following code throw an exception and reach the catch block?

try {
jQuery.parseXML('foo');
} catch(e) {
console.log(e.message);
}

@JamesMGreene

This comment has been minimized.

Show comment Hide comment
@JamesMGreene

JamesMGreene Apr 5, 2013

Collaborator
  • What OS? What version?
  • What version of PhantomJS?
  • What version of jQuery?
  • What is the context of this script?
    • An existing script on an existing page?
    • A PhantomJS-injected script onto an existing page?
    • A page.evaluate call to an existing page?
    • Run in the PhantomJS outer context?
    • REPL mode?
Collaborator

JamesMGreene commented Apr 5, 2013

  • What OS? What version?
  • What version of PhantomJS?
  • What version of jQuery?
  • What is the context of this script?
    • An existing script on an existing page?
    • A PhantomJS-injected script onto an existing page?
    • A page.evaluate call to an existing page?
    • Run in the PhantomJS outer context?
    • REPL mode?
@JamesMGreene

This comment has been minimized.

Show comment Hide comment
@JamesMGreene

JamesMGreene Apr 5, 2013

Collaborator

(But the expectation would be: "yes, it should".)

Collaborator

JamesMGreene commented Apr 5, 2013

(But the expectation would be: "yes, it should".)

@repinel

This comment has been minimized.

Show comment Hide comment
@repinel

repinel Apr 5, 2013

Actually, my example with just 'foo' is working properly. I am having problems with something like '<foo></foogoo>'.

  • What OS? What version?
    Ubuntu 12.10 AMD64 and Windows 7 64-bit
  • What version of PhantomJS?
    PhantomJS 1.9.0
  • What version of jQuery?
    Happened with 1.6.1 and 1.8.2
  • What is the context of this script?
    • An existing script on an existing page?
    • A PhantomJS-injected script onto an existing page?
    • A page.evaluate call to an existing page?
    • Run in the PhantomJS outer context?
    • REPL mode?
console.log('Started');

var page = require('webpage').create();

page.onConsoleMessage = function(msg) {
  console.log(msg);
};

page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js", function() {
    console.log('Loaded jQuery');
    page.evaluate(function() {
        try {
          console.log('Parsing XML');
          var doc = jQuery.parseXML('<foo></foogoo>');
          console.log('XML is valid? ' + (doc.length == 1));
        } catch(e) {
          console.log(e.message);
        }
    });
    phantom.exit();
});

The same JavaScript code is working as expected on jsFiddle http://jsfiddle.net/u4Amm/

repinel commented Apr 5, 2013

Actually, my example with just 'foo' is working properly. I am having problems with something like '<foo></foogoo>'.

  • What OS? What version?
    Ubuntu 12.10 AMD64 and Windows 7 64-bit
  • What version of PhantomJS?
    PhantomJS 1.9.0
  • What version of jQuery?
    Happened with 1.6.1 and 1.8.2
  • What is the context of this script?
    • An existing script on an existing page?
    • A PhantomJS-injected script onto an existing page?
    • A page.evaluate call to an existing page?
    • Run in the PhantomJS outer context?
    • REPL mode?
console.log('Started');

var page = require('webpage').create();

page.onConsoleMessage = function(msg) {
  console.log(msg);
};

page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js", function() {
    console.log('Loaded jQuery');
    page.evaluate(function() {
        try {
          console.log('Parsing XML');
          var doc = jQuery.parseXML('<foo></foogoo>');
          console.log('XML is valid? ' + (doc.length == 1));
        } catch(e) {
          console.log(e.message);
        }
    });
    phantom.exit();
});

The same JavaScript code is working as expected on jsFiddle http://jsfiddle.net/u4Amm/

@mars

This comment has been minimized.

Show comment Hide comment
@mars

mars Feb 14, 2014

Currently experiencing this issue too.

  • What OS? What version? Mac OS X 10.9.1
  • What version of PhantomJS? PhantomJS 1.9.2
  • What version of jQuery? jQuery 1.10.1
  • What is the context of this script? An existing script on an existing page: running a Jasmine spec suite

mars commented Feb 14, 2014

Currently experiencing this issue too.

  • What OS? What version? Mac OS X 10.9.1
  • What version of PhantomJS? PhantomJS 1.9.2
  • What version of jQuery? jQuery 1.10.1
  • What is the context of this script? An existing script on an existing page: running a Jasmine spec suite
@ghost

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Jul 3, 2015

I'm also experiencing this issue. Is there any workaround for this?

  • What OS? What version? Linux Mint 16
  • What version of PhantomJS? PhantomJS 1.9.8
  • What version of jQuery? jQuery 2.1.4
  • What is the context of this script? An existing script on an existing page: running a Jasmine spec suite

ghost commented Jul 3, 2015

I'm also experiencing this issue. Is there any workaround for this?

  • What OS? What version? Linux Mint 16
  • What version of PhantomJS? PhantomJS 1.9.8
  • What version of jQuery? jQuery 2.1.4
  • What is the context of this script? An existing script on an existing page: running a Jasmine spec suite
@LeMoussel

This comment has been minimized.

Show comment Hide comment
@LeMoussel

LeMoussel Jul 3, 2015

Code working properly

  • What OS? What version? Windows 7
  • What version of PhantomJS? PhantomJS 2.0.0
  • What version of jQuery? jQuery 2.1.4
  • What is the context of this script? An existing script

Result:

Started
Loaded jQuery
Parsing XML
XML is valid? false`

Code working properly

  • What OS? What version? Windows 7
  • What version of PhantomJS? PhantomJS 2.0.0
  • What version of jQuery? jQuery 2.1.4
  • What is the context of this script? An existing script

Result:

Started
Loaded jQuery
Parsing XML
XML is valid? false`

@ghost ghost removed old.Module-WebPage labels Dec 19, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment