ariya / phantomjs

Scriptable Headless Browser
http://phantomjs.org
BSD 3-Clause "New" or "Revised" License
29.46k stars 5.76k forks source link

Building phantomjs with Flash support (v1.4.1 the most probable candidate) #11179

Closed sunnybear closed 11 years ago

sunnybear commented 11 years ago

Hello. Yes, I understand that 1.4.1 is out of support, but it is the latest version which supports Flash, so this may be useful to other community members.

System: CentOS release 5.7 (Final), 32bit I've installed all the components by these guides http://rhythmicalmedia.com/?p=146 https://code.google.com/p/phantomjs/wiki/XvfbSetup All was OK (except the GIT insallation - but phantomjs-1.4.1 was in source code, so no actual usage of GIT). Xvfb has been started (also need to add strings

 # chkconfig: 345 99 50
 # description: Simple graphical server

to make chkconfig work with it).

I'm trying to lauch just loadspeed.js from examples (as command line for Xvfb tells) - under root:

DISPLAY=:0 ./phantomjs ../examples/loadspeed.js http://www.yandex.ru
Locking assertion failure.  Backtrace:
#0 /usr/lib/libxcb-xlib.so.0 [0xb53e3737]
#1 /usr/lib/libxcb-xlib.so.0(xcb_xlib_unlock+0x31) [0xb53e3891]
#2 /usr/lib/libX11.so.6 [0xb575d021]
#3 /usr/lib/libXfixes.so.3(XFixesQueryVersion+0x4b) [0xb58e8ebb]
#4 /usr/lib/qt47/libQtGui.so.4 [0xb6322d20]
#5 /usr/lib/qt47/libQtGui.so.4(_ZN19QApplicationPrivate9constructEP9_XDisplaymm+0xdf) [0xb629715f]
#6 /usr/lib/qt47/libQtGui.so.4(_ZN12QApplicationC1ERiPPci+0x83) [0xb6298093]
#7 ./phantomjs [0x806013c]
#8 /lib/libc.so.6(__libc_start_main+0xdc) [0xb5abbebc]
#9 ./phantomjs [0x8050721]
phantomjs: xcb_xlib.c:82: xcb_xlib_unlock: Assertion `c->xlib.lock' failed.
Aborted
ps axf | grep Xvfb | grep -v grep
23737 pts/2    S      0:00 Xvfb :0 -screen 0 1600x1050x24

What also need to be compiled / installed?

sunnybear commented 11 years ago

Issue is being also discussed here https://github.com/ariya/phantomjs/issues/10658

JamesMGreene commented 11 years ago

@sunnybear: If you want to give value to other community members with Flash support—and I guarantee you'd make a fair number of people happy indeed!)—I'd recommend try to figure out how to patch the current release of PhantomJS to undo all the changes that were made between 1.4.x and 1.5.0 to facilitate the removal of plugin support.

There are 128 commits between those versions: https://github.com/ariya/phantomjs/compare/1.4.1...1.5.0

However, most of them are irrelevant to your purposes, so you just need to find the ones that matter... basically anything that involves/mentions:

I did a quick scan for you and I believe it can be narrowed down a bit to this 57-commit range: https://github.com/ariya/phantomjs/compare/0d77f58...c2c80c0

If you can achieve all that, then this discussion should help you enable Flash in particular afterward: http://qt-project.org/forums/viewthread/12496/

sunnybear commented 11 years ago

@JamesMGreene: thank you very much for your comment. But I can't build from sources any version of phantomjs on CentOS 5.7 - this is the main reason of this issue. The latest builds (i.e. 1.8.2) fail with the different output, but I think resolving the upper issue also can help to provide a stable build with flash support.

JamesMGreene commented 11 years ago

BTW, explanation of the need to also undo the "headless" changes in addition to the "plugin support" changes, per past discussions of my own with @ariya:

On Linux, I'm pretty sure it takes more than just that[1] since we don't use X11 and all those windowed plugins will refuse to run. I don't know about other platforms, though.

[1] "that" → Undoing this commit: https://github.com/ariya/phantomjs/commit/8c7b586f03

sunnybear commented 11 years ago
  1. Haven't mentioned Flash plugin installation routine:

    rpm -ivh http://linuxdownload.adobe.com/adobe-release/adobe-release-i386-1.0-1.noarch.rpm
    rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-adobe-linux
    yum check-update
    yum -y install flash-plugin nspluginwrapper
    
  2. You may need xfvb-run script, I've obtained one from here http://www.minecraftwiki.net/wiki/Programs_and_Editors/Tectonicus/VPS
  3. You need to execute in shell

    export LIBXCB_ALLOW_SLOPPY_LOCK=1
    
  4. Then the command line

    xvfb-run --server-args="-screen 0, 1024x768x24" ./phantomjs ../examples/rasterize.js http://www.yandex.ru 2.png
    

    or (if Xvfb is run as a service)

    DISPLAY=:0 ./phantomjs ../examples/rasterize.js http://www.yandex.ru 2.png
    

    Gives me result - it seems it's a working example of 1.4.1 with Flash support. Oh, year!

sunnybear commented 11 years ago

Command line must contain option --load-plugins=yes - so the correct ones will be

DISPLAY=:0 ./phantomjs --load-plugins=yes ../examples/rasterize.js URL SCREENSHOT_FILE

or

xvfb-run --server-args="-screen 0, 1024x768x24" ./phantomjs --load-plugins=yes ../examples/rasterize.js URL SCREENSHOT_FILE
sunnybear commented 11 years ago

Also to emulate Flash support in phantomjs browser you need to add before page.open the following (at least plugins and mimeTypes - to pass all Flash detection tests correctly)

    page.onInitialized = function () {
        page.evaluate(function () {
            window.navigator = {
                plugins: {length: 2, 'Shockwave Flash': {name: 'Shockwave Flash', description: 'Shockwave Flash 11.6 r602'}},
                mimeTypes: {length: 2, "application/x-shockwave-flash":
                    {description: "Shockwave Flash", suffixes: "swf", type: "application/x-shockwave-flash", enabledPlugin: {description: "Shockwave Flash 11.6 r602"}}
                },
                appCodeName: "Mozilla",
                appName: "Netscape",
                appVersion: "5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22",
                cookieEnabled: true,
                language: "en",
                onLine: true,
                platform: "CentOS 5.7",
                product: "Gecko",
                productSub: "20030107",
                userAgent: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22",
            };
        });
    };
ariya commented 11 years ago

We have no intention to go back to version 1.4, let alone to reenable plugin support there. I know this information can be useful to others but it serves us little to no purpose if it is being discussed here.

Can you just create a project (perhaps by forking this one) for this purpose?

sunnybear commented 11 years ago

I'm not a C++ programmer but an entrepreneur. If you can give me rights to edit Documentation - I will create and manage (or my people will do) a special page how to lauch PhantomJS with Flash. But I not going to create a branch of this beautiful project (it's really cool).

Some additions to the upper instruction. Flash 11 from Adobe (the latest for now) seems not to work for me, downgraded to Flash 10 by the following command

rpm -ivh http://dl.atrpms.net/el5-i386/atrpms/bleeding/flash-plugin-10.2-1.i386.rpm            
ariya commented 11 years ago

@sunnybear As I wrote before, we do not want to include any materials referencing plugin support because of various reasons. It's not officially supported and we don't want to handle questions regarding its use, in particular if it's involving old versions of PhantomJS.

If you don't want to branch/fork this project, please use other approaches, e.g. writing a blog post or an article. Many good external articles are mentioned from https://github.com/ariya/phantomjs/wiki/Buzz.

Closing this issue as WONTFIX.

sunnybear commented 11 years ago

Thank you. Created a How-To article in our blog http://blog.webogroup.com/2013/04/how-to-setup-completely-headless.html Please add to buzz

JamesMGreene commented 11 years ago

Related: http://www.ryanbridges.org/2013/05/21/putting-the-flash-back-in-phantomjs/

JamesMGreene commented 11 years ago

Added both to Buzz.

scottmccaskill commented 8 years ago

I have been using PhantomJS for 3 years; version 1.9 randomly dies when creating lots of pdfs. Otherwise, it's been a great product for us. The suggested fix for this problem was 2+. Upon installing 2.1.1, I immediately ran into the issue of the zoomFactor not working at all/really huge pdfs that don't fit to A4 pages.

So I pulled master and tried to compile on Ubuntu 16.0.4 with 9GB free storage and 7.5 GB RAM. It fails every time with Creating qmake... .Done. Running configuration tests (phase 2)... No QPA platform plugin enabled! If you really want to build without a QPA platform plugin you must pass -no-qpa-platform-guard to configure. Doing this will produce a Qt that can not run GUI applications. The dependencies needed for xcb to build are listed in src/plugins/platforms/xcb/README

I have xcb installed. I have tried modifying the build.py script to add -no-qpa-platform-guard. That will compile for awhile and then die at kernel/qwidget.cpp: In member function ‘void QWidgetPrivate::show_sys()’: kernel/qwidget.cpp:7921:50: error: ‘struct QWExtra’ has no member named ‘proxyWidget’ if ((q->isWindow() && (!extra || !extra->proxyWidget)) ^ kernel/qwidget.cpp: In member function ‘void QWidgetPrivate::hide_sys()’: kernel/qwidget.cpp:8056:50: error: ‘struct QWExtra’ has no member named ‘proxyWidget’ if ((q->isWindow() && (!extra || !extra->proxyWidget)) ^

Makefile:47705: recipe for target '.obj/qwidget.o' failed make[2]: **\* [.obj/qwidget.o] Error 1 make[2]: **\* Waiting for unfinished jobs.... make[2]: Leaving directory '/home/ubuntu/phantomjs/src/qt/qtbase/src/widgets' Makefile:497: recipe for target 'sub-widgets-make_first' failed make[1]: **\* [sub-widgets-make_first] Error 2 make[1]: Leaving directory '/home/ubuntu/phantomjs/src/qt/qtbase/src' Makefile:45: recipe for target 'sub-src-make_first' failed make: **\* [sub-src-make_first] Error 2 ERROR: Failed to build PhantomJS! Building Qt Base failed. I will pay cash money for someone who can get me a build on Ubuntu 16.0.4 that 1) dies less often and 2) does not have this zoomfactor/dpi problem. Thoughts? What am I doing wrong? Thanks. Scott
puravida commented 8 years ago

@ariya @JamesMGreene Hello all! I have spent the last couple of weeks testing various platforms and open-source screenshot utilities to consider adding a failover or fallback for our primary capture technology. I have been testing with Chrome, Firefox, PhantomJS, CutyCapt, and I'm now considering to test SlimerJS (since it appears to support Flash).

My question for you is: "While I understand removing Flash support to greatly decouple dependencies and simplify development and maintanence, I read somewhere that the argument was this allows for externally supplied support. However, I do not see any documentation or mention of how one would integrate a Flash-support integration with PhantomJS that does not require constantly cross-porting (a word?) changes. So, could you elaborate on that a bit or clarify any misunderstanding I have in that?"

Without Flash, I cannot consider PhantomJS at all, which is sad b/c PhantomJS runs nearly twice as fast as my current, proprietary solution! The forks that add back Flash support, being unsupported, outdated, and cumbersome, would only add to my already overloaded code maintenance plate. Thank you for any feedback and insight! :)