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

PhantomJS not properly loading javascripts #11529

Closed
rhoot opened this issue Aug 1, 2013 · 6 comments
Closed

PhantomJS not properly loading javascripts #11529

rhoot opened this issue Aug 1, 2013 · 6 comments
Labels

Comments

@rhoot
Copy link
Contributor

rhoot commented Aug 1, 2013

This affects both 1.9.0 and 1.9.1. I have not tried master.

I have noticed that many pure javascript sites aren't loaded properly in PhantomJS (https://www.imprev.net/ui/#login and https://login.serverdensity.io/, to name just a couple). I quickly looked into it and it seems PhantomJS isn't loading all javascripts on the page. In the case of serverdensity, it actually doesn't load a single one.

Example script:

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

page.onResourceRequested = (request) ->
    console.log "#{request.method}\t#{request.url}"

page.onResourceReceived = (data) ->
    console.log "#{data.status}\t#{data.url}"

page.open 'https://login.serverdensity.io/', ->
    setTimeout ->
        phantom.exit()
    , 10000

The output from this script is:

GET https://login.serverdensity.io/
200 https://login.serverdensity.io/
200 https://login.serverdensity.io/

Looking at the source, there's nothing to suggest that they shouldn't load. So the question is, why aren't they?

@JamesMGreene
Copy link
Collaborator

This is pretty unlikely. I'd suggest inspecting the page HTML (page.content) after loading the page as I would personally suspect that the detecting PhantomJS as a bot (or something) and responding with different content.

@rhoot
Copy link
Contributor Author

rhoot commented Aug 5, 2013

I thought that as well, but I also tried printing out the HTML. Adding console.log page.content on the line above phantom.exit() in the example script, I get the following code. The script tags are clearly there.

<!DOCTYPE html><html class="launching"><head>
        <title>Server Density - Login</title>

        <base href="/">
        <link rel="stylesheet" href="/assets/css/html5-boilerplate.css">
        <link rel="stylesheet" href="/assets/css/icon-font.css">
        <link rel="stylesheet" href="/assets/css/style.css">

        <script src="/?bootstrap"></script>
        <script data-main="/app/compiled/bootstrap" src="/assets/js/libs/require/require.js"></script>
</head>
<body>

<noscript>
        &lt;p&gt;server density requires you to have javascript enabled to get all the awesome. please turn it on to use the application&lt;/p&gt;
</noscript>

<div id="app" class="clearfix">
        <div id="currentView" class="clearfix"></div>
</div>



</body></html>

@JamesMGreene
Copy link
Collaborator

OK. Next guess: the version of WebKit we are using may be too old to recognize script and link elements without type attributes.

@rhoot
Copy link
Contributor Author

rhoot commented Aug 5, 2013

Was thinking that as well, so I found this line of code being called from here. Both in the ScriptElement class.

@johnbburg
Copy link

johnbburg commented Sep 20, 2017

Sorry to resurrect an old thread (it is still open). I think I am running into this issue on 2.1.1. I haven't reliably recreated it from a scratch setup yet, but it seems like it may be related to including javascript via protocol-relative URLs. E.g. //my.domain/myJavascript.js

Edit: seems that I posted too soon. The issue isn't in phantomjs, but in another tool I am using (Behat), trying to use phantomjs.

@stale stale bot added the stale label Dec 26, 2019
@stale
Copy link

stale bot commented Dec 29, 2019

Due to our very limited maintenance capacity, we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed (see #15395 for more details). In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!

@stale stale bot closed this as completed Dec 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants