Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhantomJS hangs on even simple examples #14186

nathanejohnson opened this issue Apr 9, 2016 · 18 comments

PhantomJS hangs on even simple examples #14186

nathanejohnson opened this issue Apr 9, 2016 · 18 comments


Copy link

@nathanejohnson nathanejohnson commented Apr 9, 2016

I have built PhantomJS on Alpine Linux 3.3.3 . I have applied these two pull requests in order to get it to build:



examples/hello.js fails (as with all others tried.)

I see the same issues running 2.1.1 tag as well as current master (842715b as of this writing)

Here is an example: (note that I wait quite a while before hitting Control C)

alpineamd64:~/phantomjs$ uname -a
Linux alpineamd64 4.1.20 #1-Alpine SMP Mon Mar 21 10:06:39 GMT 2016 x86_64 Linux
alpineamd64:~/phantomjs$ cd bin
alpineamd64:~/phantomjs/bin$ ldd phantomjs 
    /lib/ (0x55b3f8a2e000) => /lib/ (0x7fb1aa93c000) => /usr/lib/ (0x7fb1aa611000) => /usr/lib/ (0x7fb1aa366000) => /usr/lib/ (0x7fb1aa12f000) => /usr/lib/ (0x7fb1a9e81000) => /lib/ (0x7fb1a9c18000) => /lib/ (0x7fb1a97fb000) => /usr/lib/ (0x7fb1a93d0000) => /usr/lib/ (0x7fb1a9064000) => /usr/lib/ (0x7fb1a7681000) => /usr/lib/ (0x7fb1a7331000) => /usr/lib/ (0x7fb1a711e000) => /lib/ (0x55b3f8a2e000) => /usr/lib/ (0x7fb1a6efe000) => /usr/lib/ (0x7fb1a6cd1000)
alpineamd64:~/phantomjs/bin$ cd ../examples/
alpineamd64:~/phantomjs/examples$../bin/phantomjs --debug=true hello.js 
2016-04-09T14:21:23 [DEBUG] CookieJar - Created but will not store cookies (use option '--cookies-file=<filename>' to enable persistent cookie storage)
2016-04-09T14:21:23 [DEBUG] Set  "http"  proxy to:  "" : 1080
2016-04-09T14:21:23 [DEBUG] Phantom - execute: Configuration
2016-04-09T14:21:23 [DEBUG]      0 objectName : ""
2016-04-09T14:21:23 [DEBUG]      1 cookiesFile : ""
2016-04-09T14:21:23 [DEBUG]      2 diskCacheEnabled : "false"
2016-04-09T14:21:23 [DEBUG]      3 maxDiskCacheSize : "-1"
2016-04-09T14:21:23 [DEBUG]      4 diskCachePath : ""
2016-04-09T14:21:23 [DEBUG]      5 ignoreSslErrors : "false"
2016-04-09T14:21:23 [DEBUG]      6 localUrlAccessEnabled : "true"
2016-04-09T14:21:23 [DEBUG]      7 localToRemoteUrlAccessEnabled : "false"
2016-04-09T14:21:23 [DEBUG]      8 outputEncoding : "UTF-8"
2016-04-09T14:21:23 [DEBUG]      9 proxyType : "http"
2016-04-09T14:21:23 [DEBUG]      10 proxy : ":1080"
2016-04-09T14:21:23 [DEBUG]      11 proxyAuth : ":"
2016-04-09T14:21:23 [DEBUG]      12 scriptEncoding : "UTF-8"
2016-04-09T14:21:23 [DEBUG]      13 webSecurityEnabled : "true"
2016-04-09T14:21:23 [DEBUG]      14 offlineStoragePath : ""
2016-04-09T14:21:23 [DEBUG]      15 localStoragePath : ""
2016-04-09T14:21:23 [DEBUG]      16 localStorageDefaultQuota : "-1"
2016-04-09T14:21:23 [DEBUG]      17 offlineStorageDefaultQuota : "-1"
2016-04-09T14:21:23 [DEBUG]      18 printDebugMessages : "true"
2016-04-09T14:21:23 [DEBUG]      19 javascriptCanOpenWindows : "true"
2016-04-09T14:21:23 [DEBUG]      20 javascriptCanCloseWindows : "true"
2016-04-09T14:21:23 [DEBUG]      21 sslProtocol : "default"
2016-04-09T14:21:23 [DEBUG]      23 sslCertificatesPath : ""
2016-04-09T14:21:23 [DEBUG]      24 sslClientCertificateFile : ""
2016-04-09T14:21:23 [DEBUG]      25 sslClientKeyFile : ""
2016-04-09T14:21:23 [DEBUG]      26 sslClientKeyPassphrase : ""
2016-04-09T14:21:23 [DEBUG]      27 webdriver : ":"
2016-04-09T14:21:23 [DEBUG]      28 webdriverLogFile : ""
2016-04-09T14:21:23 [DEBUG]      29 webdriverLogLevel : "INFO"
2016-04-09T14:21:23 [DEBUG]      30 webdriverSeleniumGridHub : ""
2016-04-09T14:21:23 [DEBUG] Phantom - execute: Script & Arguments
2016-04-09T14:21:23 [DEBUG]      script: "hello.js"
2016-04-09T14:21:23 [DEBUG] Phantom - execute: Starting normal mode
2016-04-09T14:21:23 [DEBUG] WebPage - setupFrame ""
alpineamd64:~/phantomjs/examples$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 7945
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 7945
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

Here is strace output:

Any ideas?

Copy link

@ryansch ryansch commented May 26, 2016

Reproduced with the following Dockerfile:

FROM alpine:3.3
MAINTAINER Ryan Schlesinger <>

RUN apk add --no-cache \
  build-base \
  git \
  perl \
  openssl-dev \
  flex \
  bison \
  gperf \
  ruby \
  fontconfig-dev \
  freetype-dev \
  sqlite-dev \
  icu-dev \
  libpng-dev \
  libjpeg \
  python \
  libx11-dev \
  libxext-dev \


RUN git clone git:// && \
  cd phantomjs && \
  git checkout ${PHANTOMJS_VERSION} && \
  git submodule init && \
  git submodule update

WORKDIR /phantomjs
RUN cd src/qt/qtbase && wget -O - | patch -p1
RUN cd src/qt/qtwebkit && wget -O - | patch -p1
RUN python --confirm --release --qt-config="-no-pkg-config" --git-clean-qtbase --git-clean-qtwebkit

Copy link

@ryansch ryansch commented May 27, 2016

Repro'd on 6090f54 as well. (Comment out the first patch)

Copy link

@svvac svvac commented Jun 14, 2016

Hitting the same problem. In my case the REPL doesn't even work.

I'm trying to get a musl-libc build of phantomjs working, specifically for use in Alpine Linux without the glibc-compat stuff.

I'm building from source (git tag 2.1.1) with the following patches applied:

The build process doesn't seem to run through any trouble, except for a few warnings on unused variables AFAICT (the build log is ginormous however, can't say I went through it all). However, when launching the binary, I get the REPL, but it doesn't seem to execute anything:

$ phantomjs --debug=true
2016-06-14T09:54:46 [DEBUG] CookieJar - Created but will not store cookies (use option '--cookies-file=<filename>' to enable persistent cookie storage)
2016-06-14T09:54:46 [DEBUG] Set  "http"  proxy to:  "" : 1080
2016-06-14T09:54:46 [DEBUG] Phantom - execute: Configuration
2016-06-14T09:54:46 [DEBUG]      0 objectName : ""
2016-06-14T09:54:46 [DEBUG]      1 cookiesFile : ""
2016-06-14T09:54:46 [DEBUG]      2 diskCacheEnabled : "false"
2016-06-14T09:54:46 [DEBUG]      3 maxDiskCacheSize : "-1"
2016-06-14T09:54:46 [DEBUG]      4 diskCachePath : ""
2016-06-14T09:54:46 [DEBUG]      5 ignoreSslErrors : "false"
2016-06-14T09:54:46 [DEBUG]      6 localUrlAccessEnabled : "true"
2016-06-14T09:54:46 [DEBUG]      7 localToRemoteUrlAccessEnabled : "false"
2016-06-14T09:54:46 [DEBUG]      8 outputEncoding : "UTF-8"
2016-06-14T09:54:46 [DEBUG]      9 proxyType : "http"
2016-06-14T09:54:46 [DEBUG]      10 proxy : ":1080"
2016-06-14T09:54:46 [DEBUG]      11 proxyAuth : ":"
2016-06-14T09:54:46 [DEBUG]      12 scriptEncoding : "UTF-8"
2016-06-14T09:54:46 [DEBUG]      13 webSecurityEnabled : "true"
2016-06-14T09:54:46 [DEBUG]      14 offlineStoragePath : ""
2016-06-14T09:54:46 [DEBUG]      15 localStoragePath : ""
2016-06-14T09:54:46 [DEBUG]      16 localStorageDefaultQuota : "-1"
2016-06-14T09:54:46 [DEBUG]      17 offlineStorageDefaultQuota : "-1"
2016-06-14T09:54:46 [DEBUG]      18 printDebugMessages : "true"
2016-06-14T09:54:46 [DEBUG]      19 javascriptCanOpenWindows : "true"
2016-06-14T09:54:46 [DEBUG]      20 javascriptCanCloseWindows : "true"
2016-06-14T09:54:46 [DEBUG]      21 sslProtocol : "default"
2016-06-14T09:54:46 [DEBUG]      23 sslCertificatesPath : ""
2016-06-14T09:54:46 [DEBUG]      24 sslClientCertificateFile : ""
2016-06-14T09:54:46 [DEBUG]      25 sslClientKeyFile : ""
2016-06-14T09:54:46 [DEBUG]      26 sslClientKeyPassphrase : ""
2016-06-14T09:54:46 [DEBUG]      27 webdriver : ":"
2016-06-14T09:54:46 [DEBUG]      28 webdriverLogFile : ""
2016-06-14T09:54:46 [DEBUG]      29 webdriverLogLevel : "INFO"
2016-06-14T09:54:46 [DEBUG]      30 webdriverSeleniumGridHub : ""
2016-06-14T09:54:46 [DEBUG] Phantom - execute: Script & Arguments
2016-06-14T09:54:46 [DEBUG]      script: ""
2016-06-14T09:54:46 [DEBUG] Phantom - execute: Starting REPL mode
2016-06-14T09:54:46 [DEBUG] WebPage - setupFrame ""
phantomjs> var a = 10
phantomjs> console.log(a);
phantomjs> console.log('Echo?')
phantomjs> This is not even *valid syntax*, yet it doesn't complain /o\
phantomjs> ^C
2016-06-14T09:55:52 [DEBUG] WebPage - setupFrame ""
2016-06-14T09:55:52 [DEBUG] WebPage - updateLoadingProgress: 10
2016-06-14T09:55:52 [DEBUG] WebPage - setupFrame ""
2016-06-14T09:55:52 [DEBUG] WebPage - updateLoadingProgress: 100

If anything is missing, I'd be happy to give more details.

Additional info:

$ phantomjs -v
$ ldd /usr/bin/phantomjs 
    /lib/ (0x559e6abbb000) => /lib/ (0x7f1a3da7a000) => /usr/lib/ (0x7f1a3d7cf000) => /usr/lib/ (0x7f1a3d598000) => /usr/lib/ (0x7f1a3d2ea000) => /lib/ (0x7f1a3d081000) => /lib/ (0x7f1a3cc64000) => /usr/lib/ (0x7f1a3c839000) => /usr/lib/ (0x7f1a3c4cd000) => /usr/lib/ (0x7f1a3aaea000) => /usr/lib/ (0x7f1a3a79a000) => /usr/lib/ (0x7f1a3a587000) => /lib/ (0x559e6abbb000) => /usr/lib/ (0x7f1a3a367000) => /usr/lib/ (0x7f1a3a13a000)
$ paxctl -v /usr/bin/phantomjs 
PaX control v0.9
Copyright 2004,2005,2006,2007,2009,2010,2011,2012,2014 PaX Team <>

- PaX flags: -----m-x-e-- [/usr/bin/phantomjs]
    MPROTECT is disabled
    RANDEXEC is disabled
    EMUTRAMP is disabled

md5 added a commit to appropriate/ohana-web-search that referenced this issue Jun 28, 2016
Looks like there are a number of efforts to get phantomjs working under Alpine,
but it's not quite possible.

See ariya/phantomjs#14186 as a good starting point
Copy link

@ptolemybarnes ptolemybarnes commented Aug 2, 2016

Might be the same as an issue I'm having. I'm using PhantomJS to run some jasmine specs. It locks up when encountering an undeclared variable and memory usage spikes to > 4GB.

The problem has been reproduced on 2 machines using this repo:

Run bundle then bundle exec spec:javascripts. Notice in ActivityMonitor that PhantomJS is consuming a huge amount of memory.

Curiously if you move the unknown variable within the function passed to jasmine#describe it behaves as expected.

Copy link

@mrinterweb mrinterweb commented Oct 4, 2016

I'm encountering the same issue. Been fighting with this for a day now. Going to stop now that I know this is a bug others are encountering.

Copy link

@sanmai-NL sanmai-NL commented Oct 18, 2016

May I suggest everyone who is hit by this give thumbs-up to the opening post? I think Alpine Linux is a natural OS to run (headless) automated tests on, and so it is worthwhile to quantify the level of support there is for fixing this issue.

Copy link

@ryansch ryansch commented Oct 19, 2016

We instead ditched phantomjs because of this. ☹️

Copy link

@berliner berliner commented Oct 19, 2016


Copy link

@MichielDeMey MichielDeMey commented Dec 29, 2016

We should probably rename this issue and specify that this is a musl/Alpine linux specific issue.

Copy link

@sylus sylus commented Jan 27, 2017

I posted what I think might be the issue @ ncopa/docker-phantomjs-alpine#2 (comment) for @ncopa. Hopefully can get some progress going on this issue as this is my last real blocker from leveraging only alpine containers.

Copy link

@joechlanda joechlanda commented Feb 14, 2017

+1 for getting this issue fixed. I just spend a few days getting a work around to work on my bamboo + docker w/ alpine.

My stop gap work around fix was as follows:
when setting up the webdriver also set these two.
implicitly_wait should be 0 by default but we set it again
page_load_timeout will allow us to raise TimeoutExceptions helping us later


when exiting the webdriver:

import signal

and then I also use a retry decorator on all of my selenium/phantom JS tests that use the webdriver.get() method. Example:

def tearDown(self):

Retry decorator as setup for my bamboo instance:

import time
from functools import wraps

def retry(exceptions=Exception, attempts=3, delay=3, backoff=2, logger=None):
	def deco_retry(f):

		def f_retry(*args, **kwargs):
			mtries, mdelay = attempts, delay
			while mtries > 1:
					return f(*args, **kwargs)
				except exceptions, e:
					msg = "%s: %s, Retrying in %d seconds..." % (str(e.__class__.__name__), str(e), mdelay)
					if logger:
						print msg
					mtries -= 1
					mdelay *= backoff
			return f(*args, **kwargs)

		return f_retry  # true decorator

	return deco_retry

You can set this to pick up any exception or set it explicitly to the TimeoutException from selenium. see the docs

Also a little more complex way of doing this with trying to avoid the @Retry decorator is to override the method with a test wrapper; this did not work for us as we were doing .get() calls in teardown and those were not getting retried but if you don't do that this will retry your tests 3 times.

def run(self, result=None):
	self.origTestMethodName = self._testMethodName
	self._testMethodName = "_testRetryWrapper"
	super(ATIPSeleniumTest, self).run(result)
	self._testMethodName = self.origTestMethodName

def _testRetryWrapper(self):
	testMethod = getattr(self, self.origTestMethodName)
	retryAttemptsLeft = 3

	while True:
			if retryAttemptsLeft == 0:
				print "Retrying in 3 seconds"
				retryAttemptsLeft = retryAttemptsLeft - 1

I hope this helps some people!

Copy link

@mattschofield mattschofield commented Mar 25, 2017

I don't know how it took me so long to find this thread - I'm having the same issue. From the refs, it doesn't look like there's been much movement on this yet but has anyone had any luck implementing other workarounds?

My choices at present seem to be limited to:

  1. find a new base image

I would prefer more choices.

Copy link

@vitoo vitoo commented Jun 17, 2017

@mattschofield even from other docker base image i can't make phantomjs work on my Alpine linux 3.6, i got a qt error

[WARNING] QThread::start: Thread creation error: Operation not permitted

Did you succed ?

Copy link

@thatsnotright thatsnotright commented Jul 17, 2017

@mattschofield That's the only option I've come up with, compiling it in an alpine based distro seems to have the same problem and I can't figure much out aside from it seems to have issues with a pselect call.

Copy link

@mattschofield mattschofield commented Jul 18, 2017

@vitoo @thatsnotright in the end I went with a different base image.

My feeling from all the conversations around this was that the Alpine base image just wasn't ready for phantomjs. I would require far greater knowledge of linux fundamentals to explain why this is the case.

In case it's any use for anyone, we've had pretty good success switching to a ruby:2.3.3-slim base image for our application (which uses screen-scraping powered by phantomjs) and it hasn't been too bad. It's not as small an image as alpine would give us but it's totally workable.

Copy link

@aiomaster aiomaster commented Apr 17, 2018

Just if someone finds this helpfull - in docker with alpine 3.7 I just did this to make phantomjs work:

apk add --no-cache wget nodejs

wget -qO- "" | tar xz -C /
npm config set user 0
npm install -g phantomjs-prebuilt

Copy link

@dalmatele dalmatele commented May 14, 2018

@aiomaster your solution is the best.

Copy link

@stale stale bot commented Dec 28, 2019

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

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

No branches or pull requests