Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image not saved ??!! #11

Open
imspikey opened this issue Dec 11, 2016 · 2 comments
Open

Image not saved ??!! #11

imspikey opened this issue Dec 11, 2016 · 2 comments

Comments

@imspikey
Copy link

Hello
when I run this script hello.js from:

var page = require('webpage').create();
page.open('http://example.com', function(status) {
console.log("Status: " + status);
if(status === "success") {
page.render('example.png');
}
phantom.exit();
});

example.png is not saved to disk??!!!

hello.js is at: F:\Projects\web\phantomtest
phantomsjs is at: C:\Users\imspikey\Desktop\phantomjs-2.1.1-windows\bin

lunsh.js file:

{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "phantomjs",
"request": "launch",
"file": "${workspaceRoot}/phantomtest/hello.js",
"webRoot": "${workspaceRoot}/phantomtest",
"runtimeExecutable": "C://Users//imspikey//Desktop//phantomjs-2.1.1-windows//bin//phantomjs.exe",
"runtimeArgs": [],
"sourceMaps": false
}
]
}

When I run this code from the phantomjs directory it works but when I run it from the plugin
I get the "Status: success" message but no example.png ?!
any help?

@iradul
Copy link
Owner

iradul commented Dec 11, 2016

Your image is saved in current working directory (cwd) which is unexpectedly not the one where your script nor PhantomJS executable sits in. It depends on where VSC was installed, for example on Windows it's usually C:\Program Files (x86)\Microsoft VS Code and that becomes cwd for PhantomJS when you start the debugger.
You can see what is your cwd when debugging by running this small script (in debugger):

var fs = require('fs');
console.log(fs.workingDirectory);
phantom.exit();

To workaround this you could set desired cwd at the top of your PhantomJS script with fs.changeWorkingDirectory(...) or use absolute paths when you do page.render(..).

Anyway launch.json should definitely have an option for setting cwd and I'll fix that in the next release.

@imspikey
Copy link
Author

Thank you I have checked "F:\Program Files (x86)\Microsoft VS" Code and found the "example.png" there 😃 so your solution works fine for now 👍

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

No branches or pull requests

2 participants