Phantomjs: PhantomJS doesn't throw JavaScript errors in a script file and from slots in bridge JSC objects

Created on 8 Feb 2015  Â·  21Comments  Â·  Source: ariya/phantomjs

On PhantomJS 1.9.8, this exits properly with a failure message, but on 2.0, it hangs forever. (discovered while running mocha-phantomjs tests on 2.0)

Reproduction of issue:

var page = require('webpage').create()
page.open('http://google.com', function() {
  console.log('trying to open a nonexistantfile')
  require('fs').open('nonexistantfile').read()
  console.log('all done')
})
Bug Confirmed QWebkit

Most helpful comment

@pyper sure. Here is the fix https://github.com/Vitallium/qtwebkit/commit/e09b87bfe2b3ad6004d31894ee58bd611c8e3e39 It has been landed recently.

All 21 comments

fs.read also hangs

Actually, anonymous function (open callback) works really weird.
For example, throw 42 doesn't work.

var page = require('webpage').create()
page.open('http://google.com', function() {
  throw 42; // never throws
})

Hmm, sounds like a JavaScriptCore issue? I don't recall having this behavior with Qt 4.x and PhantomJS 1.x.

@ariya yes, it is. I'll share my findings soon.

@ariya ok, here it is.

They (Digia) changed the behavior of QtConnectionObject::execute in Qt5. Now it uses JSObjectCallAsFunction to call native methods but this method has no support for forwarding exceptions.

References:
QtConnectionObject::execute - https://github.com/ariya/phantomjs/blob/master/src/qt/qtwebkit/Source/WebCore/bridge/qt/qt_runtime.cpp#L1563
JSObjectCallAsFunction - https://github.com/ariya/phantomjs/blob/master/src/qt/qtwebkit/Source/JavaScriptCore/API/JSObjectRef.cpp#L517

That's why Qt objects will not throw any exception in Qt Webkit Bridge.

Have a fix for it. Will send a PR shortly.

@Vitallium Did you ever get to publish that fix, would really help me out a ton :+1:

@Vitallium I see the "Patch Available" label on here, but for the life of me I can’t find a pull request or patch for it. Could you point me in the right direction?

@pyper sure. Here is the fix https://github.com/Vitallium/qtwebkit/commit/e09b87bfe2b3ad6004d31894ee58bd611c8e3e39 It has been landed recently.

@Vitallium Thanks Buddy!

@Vitallium I have patched and built 2.1.1 with this https://github.com/Vitallium/qtwebkit/commit/e09b87bfe2b3ad6004d31894ee58bd611c8e3e39 and it does show errors now, but it still hangs and doesn't exit; any ideas? Is that expected behaviour?

@mchampanis Could you share the binary, if you have a linux build? Thanks!

@Vitallium Do you intend to release a version with this bug fixed? One that prints a stack trace and exits when an exception is thrown?

I'd like to use PhantomJS for automated tests but I can't see how until the bug is fixed.

Wiktor, I built it on macOS but can send build instructions if you need

On Sat, 15 Apr 2017 at 11:37 Wiktor Tomczak notifications@github.com
wrote:

@mchampanis https://github.com/mchampanis Could you share the binary,
if you have a linux build? Thanks!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/ariya/phantomjs/issues/12973#issuecomment-294282836,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AACw6tTfO_t0C23VLezAtjFA77zb2FVGks5rwI_pgaJpZM4DdSb1
.

Hi Michael,

If the instructions are different from
https://github.com/ariya/phantomjs/tree/2.1.1/deploy, then please share,
definitely!

thanks

On Mon, Apr 17, 2017 at 11:26 PM, Michael Champanis <
[email protected]> wrote:

Wiktor, I built it on macOS but can send build instructions if you need

On Sat, 15 Apr 2017 at 11:37 Wiktor Tomczak notifications@github.com
wrote:

@mchampanis https://github.com/mchampanis Could you share the binary,
if you have a linux build? Thanks!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://github.com/ariya/phantomjs/issues/12973#issuecomment-294282836
,
or mute the thread
t0C23VLezAtjFA77zb2FVGks5rwI_pgaJpZM4DdSb1>
.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/ariya/phantomjs/issues/12973#issuecomment-294598052,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ASzdWd5HE-gwm0XxeVU5VKHc646eio-tks5rw9kfgaJpZM4DdSb1
.

Wiktor:

git clone [email protected]:ariya/phantomjs.git
cd phantomjs
git checkout 2.1
git submodule init
git submodule update

Apply https://github.com/Vitallium/qtwebkit/commit/e09b87bfe2b3ad6004d31894ee58bd611c8e3e39 to src/qt/qtwebkit/Source/WebCore/bridge/qt/qt_runtime.cpp

sudo apt-get install build-essential g++ flex bison gperf ruby perl \
   libsqlite3-dev libfontconfig1-dev libicu-dev libfreetype6 libssl-dev=1.0.1t-1+deb8u2 \
   libpng-dev libjpeg-dev python libx11-dev libxext-dev ttf-mscorefonts-installer
python build.py --jobs 4 --confirm

@Vitallium On page error still process does not exits. Is there any other patch for this issue ?

@tprdeepaklal, try put this handler at the top of your script:

phantom.onError = function(msg, trace) {
    var msgStack = [msg];
    if (trace && trace.length) {
        trace.forEach(function(t) {
            msgStack.push(' -> ' + t.file + ': ' + t.line + (t.function ? ' (in function "' + t.function +'")' : ''));
        });
    }    
    console.log('\n' + msgStack.join('\n') + '\n');
    phantom.exit(1);
};

@mchampanis Already have onError handlers as "page.onError" and "phantom.onError"
but it hangs and control were not reaching "page.onError" method

@mchampanis Can u explain me, how will this resolve my issue ?

https://github.com/ariya/phantomjs/pull/14111/files - mepard committed on Mar 17, 2016

screen shot 2017-04-25 at 5 47 03 pm

Was this page helpful?
0 / 5 - 0 ratings