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

PhantomJS is broken out-of-box when installed on Ubuntu 16.04 with apt #14900

Closed
mileserickson opened this issue Mar 16, 2017 · 3 comments
Closed
Labels

Comments

@mileserickson
Copy link

mileserickson commented Mar 16, 2017

  1. Which version of PhantomJS are you using? Tip: run phantomjs --version.
    2.11

  2. What steps will reproduce the problem?

    1. Launch an EC2 instance (t2.micro is adequate) with Ubuntu 16.04 (ami-a58d0dc5)
    2. sudo apt-get update
    3. sudo apt-get install phantomjs
    4. phantomjs --version returns:
QXcb connection: Could not connect to display
PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.
Aborted

Same behavior has been verified on a clean installation of Ubuntu 16.04 Server running on a local VM.

  1. Which operating system are you using?
    Ubuntu 16.04

  2. Did you use binary PhantomJS or did you compile it from source?
    Binary

  3. Please provide any additional information below.
    This also affects operation with Selenium:

selenium.common.exceptions.WebDriverException: Message: Service phantomjs unexpectedly exited. Status code was: -6

Workaround: Setting QT_QPA_PLATFORM=offscreen resolves this issue.

@mileserickson mileserickson changed the title PhantomJS not functional when installed on Ubuntu 16.04 with apt PhantomJS is broken out-of-box when installed on Ubuntu 16.04 with apt Mar 16, 2017
@balinabbb
Copy link

I ran into exactly the same error. The workaround of @mileserickson resolves the issue, but won't solve my problem. I am using phantomjs with selenium in python to create PDFs.

phantomjs --version 2.1.1 if QT_QPA_PLATFORM=offscreeen, else crashing:

PhantomJS has crashed. Please read the bug reporting guide at
<http://phantomjs.org/bug-reporting.html> and file a bug report.
Aborted (core dumped)

However if i am using this offscreen environment variable, pdf generation won't have proper paper size, and texts do not appear at all.
Usage:

    def create_pdf(url):
        driver = get_webdriver(request)
        driver.command_executor._commands['executePhantomScript'] = ('POST', '/session/$sessionId/phantom/execute')
        driver.get(url)

        def execute(script, args=[]):
            driver.execute('executePhantomScript', {'script': script, 'args': args})

        execute('''this.paperSize = {format: "A4", orientation: "portrait" };''')
        execute('''this.render("{}")'''.format('tmp.pdf'))


    def get_webdriver(request):
        regex = re.compile('^HTTP_')
        headers = dict((regex.sub('', header), value) for (header, value)
                   in request.META.items() if header.startswith('HTTP_'))
        for key, value in headers.items():
        webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.{}'.format(key)] = value
        return webdriver.PhantomJS('phantomjs')

Any quick help is appreciated! I really need to solve this issue in a short time.
Cheers,
Bálint

@niklasp
Copy link

niklasp commented Oct 18, 2017

did you solve it?

@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