Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Zombie.JS doesn't support javascript loaded via document.write #250

Closed
ThePixelDeveloper opened this issue Jan 4, 2012 · 4 comments
Closed

Comments

@ThePixelDeveloper
Copy link

Hi,

I've been having trouble with zombie.js testing when using the Google Maps API. I originally thought the problem was with the resources using query parameters in the URL. This appeared to be incorrect, here's my test for that:

css = new Browser();
css.visit('http://other.localhost/bugs/zombiejs/gmaps/css.html', function() {
    console.log();
    console.log('Calling css.html (CSS loaded with query string ...');
    console.log('Title : ' + css.text('title'));
});

Where css.html was

<!doctype html>
<html>
    <head>
        <title>Google Maps ZombieJS Bug</title>
        <link href="reset.css?time=1325674256" rel="stylesheet" type="text/css"></link>
    </head>
    <body>
        <p id="hello">Hello World</p>
    </body>
</html>

Here's my test case for zombie for testing to see if the bug is indeed a problem with document.write loaded scripts.

test case

write = new Browser();
write.visit('http://other.localhost/bugs/zombiejs/gmaps/write.html', function() {
    console.log();
    console.log('Calling write.html (Javascript loaded via document.write...');
    console.log('Title : ' + write.text('title'));
});

write.html

<!doctype html>
<html>
    <head>
        <title>Google Maps ZombieJS Bug</title>
        <script src="write.js" type="text/javascript"></script>
    </head>
    <body>
        <p id="hello">Hello World</p>
    </body>
</html>

write.js

var src = 'head.js';

document.write('<' + 'script src="' + src + '"' +
                   ' type="text/javascript"><' + '/script>');

head.js

alert('Bye World');

output

Calling write.html (Javascript loaded via document.write...
Title : <!doctype html>
<html>
    <head>
        <title>Google Maps ZombieJS Bug</title>
        <script src="write.js" type="text/javascript"></script>
    </head>
    <body>
        <p id="hello">Hello World</p>
    </body>
</html>

Using zombie@0.12.10

@assaf
Copy link
Owner

assaf commented Jan 4, 2012

No it doesn't. The default HTML parser doesn't support document.write.

I highly recommend not using document.write because it blocks the rendering loop, whereas adding script element allows JavaScript evaluating in parallel with page rendering for faster page speed.

@ThePixelDeveloper
Copy link
Author

The problem was encountered when loading the Google Maps API, something I (and probably Google too) can't change too easily. I found a workout to my specific problem which was to add a callback argument to the URL which forces the method you described.

In the case of that not being possible I'd still ask you to support it. You even say you support it in your PDF under Readiness.

@assaf
Copy link
Owner

assaf commented Jan 4, 2012

We're using the Google Maps with Zombie with no issues. Probably different part of it.

I removed the reference to document.write when we switched HTML parsers, sorry that it somehow snuck back in there.

@ThePixelDeveloper
Copy link
Author

Since I worked around this issue and we agree it's not a bug, I'm closing this issue. Thanks assaf.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants