file:// XHR support

132 views
Skip to first unread message

Lindsey Simon

unread,
Jan 23, 2012, 1:29:19 PM1/23/12
to phan...@googlegroups.com
Any reason why phantomjs doesn't allow file protocol XHRs?

I've been running my tests with the chrome flag --allow-file-access-from-files to preclude the need to run a static web server.

I see the phantomjs server module as a simple alternative here, but it looks like I'll need to implement it to read files requested from the filesystem with the fs module and output them, as there's not a built in basic static file server - is that right, or did I miss an example that does this already?

Thanks so much - phantomjs looks like a great project for continuous integration testing!

Ariya Hidayat

unread,
Jan 23, 2012, 1:34:08 PM1/23/12
to phan...@googlegroups.com
> Any reason why phantomjs doesn't allow file protocol XHRs?

Did you try localToRemoteUrlAccessEnabled? See
http://code.google.com/p/phantomjs/wiki/Interface for details.


--
Ariya Hidayat, http://ariya.ofilabs.com

Lindsey Simon

unread,
Jan 23, 2012, 1:45:35 PM1/23/12
to phan...@googlegroups.com
Hi Ariya,
Here's what I'm doing:

$  /usr/local/bin/phantomjs --local-to-remote-url-access=yes tests/phantomjs_closure_test_runner.js /Users/elsigh/src/twist/server/frontend/tests/shared/index.htmlStarting...
Unable to access network, status:fail

But if, in another shell, I do:
mongoose -p 8000

then

$  /usr/local/bin/phantomjs tests/phantomjs_closure_test_runner.js http://localhost:8000/tests/shared/index.htmlStarting...
'waitFor()' finished in 636ms.
Report--------
Twist Shared JS Tests [PASSED]
localhost:8000/tests/shared/index.html
18 of 18 tests run in 19ms.
18 passed, 0 failed.
1 ms/test. 14 files loaded.

Ariya Hidayat

unread,
Jan 23, 2012, 4:43:17 PM1/23/12
to phan...@googlegroups.com
Does giving the explicit file:/// scheme in the URL change anything?

Lindsey Simon

unread,
Jan 23, 2012, 4:53:19 PM1/23/12
to phan...@googlegroups.com
Why yes, yes it does iff I specify the full path to the index.html 
Easy enough to script that. =)
Thanks!

If you'd like a version of the runner for Google Closure jsunit I can send a pull request with the one I cooked up, but it's pretty basic and I don't know if it would benefit many.

Reply all
Reply to author
Forward
0 new messages