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

PhantomJS 2 remote debugging is broken #12864

Closed
iradul opened this issue Jan 7, 2015 · 53 comments
Closed

PhantomJS 2 remote debugging is broken #12864

iradul opened this issue Jan 7, 2015 · 53 comments

Comments

@iradul
Copy link
Contributor

iradul commented Jan 7, 2015

After running phantomjs with --remote-debugger-port=8080 and trying to debug with Google Chrome (Version 39.0.2171.95) "about:blank" link is missing. Also I tried to forcefully go to http://127.0.0.1:8080/webkit/inspector/inspector.html?page=1 but that produces empty page with no debugging capabilities.
Tested on Windows 7 with PhantomJS 2.0 built from source.

@Pharb
Copy link

Pharb commented Jan 8, 2015

The remote debugger works on Ubuntu with the latest PhantomJS master built from source, but the links to the webkit inspector are broken.

What's the HTML source of http://127.0.0.1:8080 ?

For me it's:

<html><head><title>Remote Web Inspector</title></head><body><ul>
<li><a href="/webkit/inspector/inspector.html?page=1"></li>
</ul></body></html>

The link http://localhost:8080/webkit/inspector/inspector.html?page=1 though works on Ubuntu, maybe it's more broken on Windows.

@iradul
Copy link
Contributor Author

iradul commented Jan 8, 2015

With http://127.0.0.1:8080 I'm getting exactly the same HTML source that you are getting.
But by following the link http://localhost:8080/webkit/inspector/inspector.html?page=1 browser is getting empty page with 404 status: HTTP/1.0 404 Not OK

@vitallium
Copy link
Collaborator

Confirmed.

@vitallium
Copy link
Collaborator

Fixed in #12899

@vitallium vitallium added this to the Release 2.0 milestone Jan 24, 2015
@ariya ariya modified the milestones: Release 2.0.1, Release 2.0 Jan 24, 2015
vitallium added a commit that referenced this issue Jan 24, 2015
@iradul
Copy link
Contributor Author

iradul commented Jan 26, 2015

I don't think this is fixing the problem (tested in Windows only). Remote debugger inspector page still not shows about:blank link. This time opening http://127.0.0.1:8080/webkit/inspector/inspector.html?page=1 in Chrome will load inspector page, so no more 404 code, but debugging is still not working. You can't set proper breakpoints inside __run function (or you can but they are ignored), though you can execute script with __run() call from console. I also noticed that GUI is different from what we had in PhantomJS 1.9 (probably because of newer WebKit version).

@iradul
Copy link
Contributor Author

iradul commented Jan 27, 2015

This is workaround that works for me, in utils.cpp replace loadJSForDebug with this:

bool loadJSForDebug(const QString& jsFilePath, const QString &jsFileLanguage, const Encoding& jsFileEnc, const QString& libraryPath, QWebFrame* targetFrame, const bool autorun)
{
    QString scriptPath = findScript(jsFilePath, libraryPath);
    QString scriptBody = jsFromScriptFile(scriptPath, jsFileLanguage, jsFileEnc);

    if (!autorun) {
        scriptBody = "function __run() {\n" + scriptBody + "\n}";
    }

    targetFrame->evaluateJavaScript(scriptBody, QString("debugger"));

    return true;
}

Then while remote debugging there will be (no domain) item in Sources panel and inside of it will be debugger from where you can properly set breakpoints. Also for me this debugger page is accessible and can be seen only using arrow keys and not by mouse.
Side effect is that there is no more need for remote_debugger_harness.html resource.

@vitallium
Copy link
Collaborator

@iradul can you please show me a small example? In my case I can debug JS code (on Windows).

@iradul
Copy link
Contributor Author

iradul commented Feb 2, 2015

Using PhantomJS 2.0 binary built from source (remote debugging with binary from website doesn't work at all) and running remote debugger on this test.js script:

require('webpage').create().open('http://google.com', function() {
    console.log('ok!');
    phantom.exit();
});
phantomjs.exe --remote-debugger-port=8080 test.js

with Google Chrome I'm getting this:
debugger_01

Now if I open http://localhost:8080/webkit/inspector/inspector.html?page=1 manually see below:
debugger_02

I'm getting same behavior on 3 different Windows 7 machines.

vitallium added a commit that referenced this issue Feb 7, 2015
They are already linked in QtWebkit on Linux/OS X.

(See issue #12864 and #12899).
@ariya
Copy link
Owner

ariya commented Mar 1, 2015

@vitallium With your check-in in 2.0 branch (to include Web Inspector resource, from around Jan 24), I assume this issue is fully addressed? If yes, then probably it's a good idea for us to roll out 2.0.1 with this fix.

@vitallium
Copy link
Collaborator

@ariya I can, but there are still a small bunch of issues, that I'd like to fix. I'll list them here #12970

@ariya
Copy link
Owner

ariya commented Mar 5, 2015

@vitallium Those can still go to 2.1, don't they?

@vitallium
Copy link
Collaborator

@ariya I think so.

@aschmalzhaf
Copy link

Can anyone confirm that the changes done in February fix the reported issue?
PhantomJS is completely new to me, but when I did a build two days ago on Windows (branch 2.0 - I can see the changes) I still see the behavior described by iradul on Feb. 2nd in this thread.

Has anybody else tried to buld PhantomJS from sources - and saw a working debugger?

@iradul
Copy link
Contributor Author

iradul commented May 6, 2015

Issue is not completely fixed, as I explained here.

@aschmalzhaf
Copy link

@iradul, I asked because the fix was done on Feb 5th - your comment was written on Feb 2nd (see fix here: 8e8546b).
So I thought when I read the thread that it is actualy fixed (or: should be...).

Thanks for your statement here, again, that it isn't completely fixed.

@LeMoussel
Copy link

One idea when PhantomJS Release 2.0.1 will be available to download?

@bedney
Copy link

bedney commented Jul 9, 2015

Still seeing the issues that @iradul was seeing on Feb 5th. Any ETA on 2.0.1?

vitallium added a commit to vitallium/phantomjs that referenced this issue Aug 3, 2015
vitallium added a commit to vitallium/phantomjs that referenced this issue Aug 3, 2015
As @iradul suggested, simplify resource loading in remote debug mode.
After this change we don't need remote_debugger_harness.html anymore.
And breakpoints will work now again.

Issue ariya#12864
@iradul
Copy link
Contributor Author

iradul commented Feb 8, 2017

You should not use --remote-debugger-autorun=true
With that option on phantom will immediately execute __run() internally so while you're loading localhost:9000 into Chrome your phantom script probably already ended.

@scottgrohusky
Copy link

I think this is a dupe issue which is open.

I ran:

phantomjs --remote-debugger-port=9000 practice2/chapter01/recipe08.js

and

phantomjs --remote-debugger-port=9000 --proxy-type=none practice2/chapter01/recipe08.js

Breakpoints are still not being hit and __run() does not output anything.

about_blank_missing2

no_breakpoints_or_console

@sontek
Copy link

sontek commented Feb 14, 2017

I'm seeing the same thing, the console doesn't actually run the __run() command, it inserts a newline in Chrome. The console doesn't work at all in Firefox. It works perfectly in safari though.

@jesobreira
Copy link

Same issue. __run() + enter just adds a line feed on the console window and I am unable to get it running. Chrome on Ubuntu 16.10.

@wgiroir
Copy link

wgiroir commented Feb 17, 2017

I have also verified that this failed on using Chrome and Firefox but works with Safari

@jesobreira
Copy link

@wgiroir what OS are you using? I couldn't get it working on Safari on Win7.

@sontek
Copy link

sontek commented Feb 17, 2017

I'm safari + OSX

@wgiroir
Copy link

wgiroir commented Feb 21, 2017

I was running Safari on OSX and phantomjs on CentOS 7

@jesobreira
Copy link

I could run the debug using a very old Chrome version (Chrome 17) that I download here (run sandboxie-d as I can't confirm the procedence of it, although it worked with me - do not use it for browsing, use it for debugging your PhantomJS scripts only).

@Galleleo
Copy link

Arora works for me! It's a browser based on Qt and WebKit and displays pages like Safari does. I tried Chrome on Ubuntu 16.10 as well as Safari 5.0.5 in Wine but Arora is (so far) the only browser that executes __run()

@lewsid
Copy link

lewsid commented Mar 23, 2017

Any word on this? I'm running PhantomJS 2.1.1 on OSX and the debugger simply doesn't work in any browser I try. I get the same thing others have reported: Entering the __run() command returns nothing, and no breakpoints are ever hit.

@lewsid
Copy link

lewsid commented Mar 24, 2017

For those like me still having trouble, I've found that using an old version of Chromium works well, if your default browser is Chrome. Here's a link to a 2014 build of Chromium that I've had luck getting to work with PhantomJS's remote debugger: https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Mac%2F280075%2Fchrome-mac.zip?generation=1409176787550000&alt=media

@jumoreno
Copy link

@lewisd, I can confirm I can get chrome debugger to work in the old Chromium version. Will try and understand why this is and post on here if I find anything. I have been looking for other remote debugging breakpoint options for casperjs and will post here if I find anything that works as well. Seems like we need to add support for latest Chrome though.

@iradul
Copy link
Contributor Author

iradul commented Mar 29, 2017

For those who use Code editor, you can use PhantomJS debugger extension.

@twalpole
Copy link

This is because the protocol used by Chrome changed after the Webkit- Blink engine split.

@lewsid
Copy link

lewsid commented Mar 29, 2017

This issue should be re-opened, no?

@jumoreno
Copy link

@iradul thanks for the heads up on the Code editor debugger extension -> do you happen to know runtime configuration required for a Mac? Took a quick look here so far and played a bit with it but no success so far.

@iradul
Copy link
Contributor Author

iradul commented Mar 31, 2017

@jumoreno, hmm never tested on Mac but should be straight forward if you follow steps from documentation, check those out:
https://marketplace.visualstudio.com/items?itemName=iradul.debugger-for-phantomjs
https://github.com/iradul/vscode-phantomjs-debug (raise an issue if needed)

@twalpole
Copy link

@jumoreno Also on a Mac it should work using Safari since IIRC it still uses the same protocol (WebKit based)

@thorn0
Copy link

thorn0 commented Apr 12, 2017

This must help: node-inspector/node-inspector#951 (comment)

@mingjunz
Copy link

anyone have workaround for this problem?

@BlackZork
Copy link

@mingjunz, two workrounds:

  • Use Chromium 50.x
  • Try Tizen Console Fix extension for Chrome.

@ghost ghost removed the 2.0 Regression label Jan 10, 2018
@ghost ghost removed this from the Release 2.1 milestone Jan 10, 2018
@stale stale bot added the stale label Dec 25, 2019
@stale
Copy link

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!

@stale stale bot closed this as completed Dec 28, 2019
@brittotprince
Copy link

brittotprince commented May 21, 2021

I had the same issue and was having a hard time finding chrome 50.x
Attaching the link below for future use
Chrome version: 50.0.2657.12:

Disclaimer: The below project helped me get this easily. Utilize it in case you need any other version of chrome.
https://vikyd.github.io/download-chromium-history-version/#/

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

No branches or pull requests