This repository has been archived by the owner. It is now read-only.

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

Closed
nathanboktae opened this Issue Feb 7, 2015 · 21 comments

Comments

Projects
None yet
9 participants
@nathanboktae

nathanboktae commented Feb 7, 2015

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')
})
@nathanboktae

This comment has been minimized.

Show comment
Hide comment
@nathanboktae

nathanboktae Feb 7, 2015

fs.read also hangs

nathanboktae commented Feb 7, 2015

fs.read also hangs

@Vitallium Vitallium added this to the Release 2.0.1 milestone Feb 9, 2015

@Vitallium Vitallium self-assigned this Feb 9, 2015

@Vitallium

This comment has been minimized.

Show comment
Hide comment
@Vitallium

Vitallium Feb 9, 2015

Collaborator

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
})
Collaborator

Vitallium commented Feb 9, 2015

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
})
@ariya

This comment has been minimized.

Show comment
Hide comment
@ariya

ariya Feb 14, 2015

Owner

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

Owner

ariya commented Feb 14, 2015

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

@Vitallium

This comment has been minimized.

Show comment
Hide comment
@Vitallium

Vitallium Feb 14, 2015

Collaborator

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

Collaborator

Vitallium commented Feb 14, 2015

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

@Vitallium

This comment has been minimized.

Show comment
Hide comment
@Vitallium

Vitallium Feb 15, 2015

Collaborator

@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.

Collaborator

Vitallium commented Feb 15, 2015

@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.

@Vitallium

This comment has been minimized.

Show comment
Hide comment
@Vitallium

Vitallium Feb 15, 2015

Collaborator

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

Collaborator

Vitallium commented Feb 15, 2015

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

nathanboktae added a commit to nathanboktae/mocha-phantomjs-core that referenced this issue May 14, 2015

@LinusU

This comment has been minimized.

Show comment
Hide comment
@LinusU

LinusU Jun 15, 2015

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

LinusU commented Jun 15, 2015

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

@Vitallium Vitallium added Webkit and removed old.Domain-WebKit labels Aug 22, 2015

@zackw zackw modified the milestones: Release 2.0.1, Release 2.1 Dec 23, 2015

@zackw zackw modified the milestones: Release 2.2, Release 2.1 Feb 3, 2016

@Vitallium Vitallium changed the title from attempting to opening a non-existant file after loading a page hangs phantomjs (6-line repo included) to PhantomJS doesn't throw JavaScript errors in a script file and from slots in bridge JSC objects Feb 26, 2016

@pyper

This comment has been minimized.

Show comment
Hide comment
@pyper

pyper Mar 31, 2016

@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 commented Mar 31, 2016

@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?

@Vitallium

This comment has been minimized.

Show comment
Hide comment
@Vitallium

Vitallium Apr 1, 2016

Collaborator

@pyper sure. Here is the fix Vitallium/qtwebkit@e09b87b It has been landed recently.

Collaborator

Vitallium commented Apr 1, 2016

@pyper sure. Here is the fix Vitallium/qtwebkit@e09b87b It has been landed recently.

@pyper

This comment has been minimized.

Show comment
Hide comment
@pyper

pyper Apr 1, 2016

@Vitallium Thanks Buddy!

pyper commented Apr 1, 2016

@Vitallium Thanks Buddy!

@mchampanis

This comment has been minimized.

Show comment
Hide comment
@mchampanis

mchampanis Mar 3, 2017

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

mchampanis commented Mar 3, 2017

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

@wiktortomczak

This comment has been minimized.

Show comment
Hide comment
@wiktortomczak

wiktortomczak Apr 15, 2017

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

wiktortomczak commented Apr 15, 2017

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

@wiktortomczak

This comment has been minimized.

Show comment
Hide comment
@wiktortomczak

wiktortomczak Apr 15, 2017

@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.

wiktortomczak commented Apr 15, 2017

@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.

@mchampanis

This comment has been minimized.

Show comment
Hide comment
@mchampanis

mchampanis Apr 17, 2017

mchampanis commented Apr 17, 2017

@wiktortomczak

This comment has been minimized.

Show comment
Hide comment
@wiktortomczak

wiktortomczak Apr 18, 2017

wiktortomczak commented Apr 18, 2017

@mchampanis

This comment has been minimized.

Show comment
Hide comment
@mchampanis

mchampanis Apr 20, 2017

Wiktor:

git clone git@github.com:ariya/phantomjs.git
cd phantomjs
git checkout 2.1
git submodule init
git submodule update

Apply Vitallium/qtwebkit@e09b87b 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

mchampanis commented Apr 20, 2017

Wiktor:

git clone git@github.com:ariya/phantomjs.git
cd phantomjs
git checkout 2.1
git submodule init
git submodule update

Apply Vitallium/qtwebkit@e09b87b 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
@tprdeepaklal

This comment has been minimized.

Show comment
Hide comment
@tprdeepaklal

tprdeepaklal Apr 23, 2017

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

tprdeepaklal commented Apr 23, 2017

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

@mchampanis

This comment has been minimized.

Show comment
Hide comment
@mchampanis

mchampanis Apr 23, 2017

@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 commented Apr 23, 2017

@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);
};
@tprdeepaklal

This comment has been minimized.

Show comment
Hide comment
@tprdeepaklal

tprdeepaklal Apr 25, 2017

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

tprdeepaklal commented Apr 25, 2017

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

@mchampanis

This comment has been minimized.

Show comment
Hide comment
@tprdeepaklal

This comment has been minimized.

Show comment
Hide comment
@tprdeepaklal

tprdeepaklal Apr 25, 2017

@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

tprdeepaklal commented Apr 25, 2017

@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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.