Phantom doesn't open a page unless running through a proxy - node.js

I need to scrape a website, decided to use Phantomjs. And because I love node I also thought it's ok to use Phantom npm package.
And did exactly as it's shown in readme:
phantom = require 'phantom'
phantom.create (ph)->
ph.createPage (page)->
page.open "http://stackoverflow.com", (status)->
console.log "opened stackoverflow?", status
page.evaluate (-> document.title), (result)->
console.log "Page title is #{result}"
ph.exit()
Now, strangely that didn't work first time I tried. I decided to pull up Charles and see if actually any requests are going out. And then suddenly it worked. Both messages show up in the console. Now I wonder, why it doesn't work without Charles running?

Related

socket.io node.js with beaglebone issues

I never normally post stuff here asking why something isn't working, but i've been struggling all day with this issue and hope that someone might be familiar with what's happening and could help.
I took an example from github on how to control GPIOs on the beaglebone black over wi-fi by using socket.io : github.com/lgxlogic/BoneScript-SocketIO
I'm not an expert with javascript but when I follow the exact instructions given and and run the HtmlLedDemo.js file, I get the following error below. My version of node is v.5.9.0 . I have tried updating socket.io and still the same problem. Many thanks in advance.
root#beaglebone:/var/lib/cloud9# node HtmlLedDemo.js
Option log level is not valid. Please refer to the README.
Option browser client minification is not valid. Please refer to the README.
Option browser client etag is not valid. Please refer to the README.
Server running on: http://192.168.0.87:8080
/var/lib/cloud9/node_modules/bonescript/src/my.js:245
callback(resp);
^
TypeError: callback is not a function
at onUnloadSlot (/var/lib/cloud9/node_modules/bonescript/src/my.js:245:13)
at unloadSlot (/var/lib/cloud9/node_modules/bonescript/src/my.js:235:13)
at onWriteSlots (/var/lib/cloud9/node_modules/bonescript/src/my.js:210:43)
at onReadSlots (/var/lib/cloud9/node_modules/bonescript/src/my.js:199:13)
at onFindCapeMgr (/var/lib/cloud9/node_modules/bonescript/src/my.js:174:9)
at Object.exports.load_dt (/var/lib/cloud9/node_modules/bonescript/src/my.js:157:5)
at onDTBOExists (/var/lib/cloud9/node_modules/bonescript/src/my.js:332:26)
at onDTBOExistsTest (/var/lib/cloud9/node_modules/bonescript/src/my.js:279:13)
at Object.exports.create_dt (/var/lib/cloud9/node_modules/bonescript/src/my.js:274:9)
at Object.exports.setPinMode (/var/lib/cloud9/node_modules/bonescript/src/hw_capemgr.js:102:12)
root#beaglebone:/var/lib/cloud9#
Your error message says "callback is not a function". If you have a look at the supplied call stack, you can see that on line 245 of your "my.js" file, you attempt to call a function by the variable name callback. What this error message tells you is that whatever this variable contains, it is not a function.

React FacebookAuth Error: FB.login() called before FB.init()

I'm using the admin-on-rest npm package starter project and trying to plug in a simple SSO Facebook login button using the FacebookAuth npm package. Every time I try to click the "Login" button, I get the following error:
FB.login() called before FB.init()
I'm using an .env file with the following variable: REACT_APP_FACEBOOK_APP_ID and setting it to the right value. I even did console.log() within my app and can see it output.
I checked and I'm only loading the FB SDK once, not multiple times (this was a common issue reported on other threads).
Ok, it turned out to be something pretty dumb, but something to point out nonetheless!
In my .env file, I had accidentally placed a semicolon (;) at the end of the declaration, like this:
REACT_APP_FACEBOOK_APP_ID = XXXXXXXXXXXX;
Apparently .env files do NOT like semi-colons. This was just very difficult to figure out from the error above.
So if any of you want to pull your hair out because of this issue, and you're using similar tech, check to make sure you're syntactically kosher EVERYWHERE variables are being declared.
the funny thing was i forgot to replace your-app-id with my app id:
<script>
FB.init({
appId: 'your-app-id',
autoLogAppEvents: true,
xfbml: true,
version: 'v8.0'
});
</script>

webdriver-sync running asynchronously?

I'm trying to create selenium tests that run each step synchronously, without using .then(), or async/await. The reason for this is that I want to create a set of functions that allow pretty much anyone on our test team, almost regardless of tech skills to write easy to read automated tests. It looks to me like webdriver-sync should give me exactly what I want. However, the following dummy code is producing problems:
var wd = require('webdriver-sync');
var By = wd.By;
var Chromedriver = wd.Chromedriver;
var driver = new Chromedriver;
driver.get('https://my.test.url');
var myButton = driver.findElement(By.cssSelector('[id*=CLICK_ME]'));
myButton.click();
It tries to run - browser is launched, and page starts to load... but the steps are not executed synchronously - it goes on and tries to find and click "myButton" before the page has finished loading, throwing a "no such element" error... which to me kinda defeats the point of webdriver-sync?! Can someone tell me where I am going wrong?
FWIW, I have webdriver-sync 1.0.0, node v7.10.0, java 1.8.0_74, all running on CentOS 7.
Thanks in advance!
You need to put double-quotes around "CLICK_ME" as it's a string value.
Generally, though, it's a good idea to Wait for specific elements because dynamic pages are often "ready" before all their elements have been created.

nodejs browser-sync - logging

im very new to nodejs but was wondering if the following was easily possible to achieve.
I use Gulp along with browser-sync plugin. I was wondering if there was a way to log every time the browser gets re-injected with the domain and time over a port range. The reason for this being I want to be able to plot productivity over projects without having to manually record this and this seems to be the most logical solution.
Is there anything out there like this or could this easily be added into a Gulp file?
Many thanks, Luke
There are some options and you can use the emitter to react to events like stream:changed, browser:reload, client:connected, connection,...
example:
var bs = require("browser-sync").create();
bs.init({}); //http://www.browsersync.io/docs/options/
....
bs.emitter.on("file:reload", function(){
console.log("File reload - Details:"+arguments)
});

Node JS Express Boilerplate and rendering

I am trying out node and it's Express framework via the Express boilerplate installation. It took me a while to figure out I need Redis installed (btw, if you're making a boilerplate either include all required software with it or warn about the requirement for certain software - Redis was never mentioned as required) and to get my way around the server.js file.
Right now I'm still a stranger to how I could build a site in this..
There is one problem that bugs me specifically - when I run the server.js file, it says it's all good. When I try to access it in the browser, it says 'transferring data from localhost' and never ends - it's like render doesn't finish sending and never sends the headers. No errors, no logs, no nothing - res.render('index') just hangs. The file exists, and the script finds it, but nothing ever happens. I don't have a callback in the render defined, so headers should get sent as usual.
If on the other hand I replace the render command with a simple write('Hello world'); and then do a res.end();, it works like a charm.
What am I doing wrong with rendering? I haven't changed a thing from the original installation btw. The file in question is index.ejs, it's in views/, and I even called app.register('.ejs', require('ejs')); just in case before the render itself. EJS is installed.
Also worth noting - if I do a res.render('index'); and then res.write('Hello'); immediately afterwards, followed by res.end();, I do get "Hello" on the screen, but the render never happens - it just hangs and says "Transferring data from localhost". So the application doesn't really die or hang, it just never finishes the render.
Edit: Interesting turn of events: if I define a callback in the render, the response does end. There is no more "Transferring data...", but the view is never rendered, neither is the layout. The source is completely empty upon inspection. There are no errors whatsoever, and no exceptions.
Problem fixed. It turns our render() has to be the absolute last command in a routing chain. Putting res.write('Hello'); and res.end(); after it was exactly what broke it.
I deleted everything and wrote simply res.render('index') and it worked like a charm. Learn from my fail, newbies - no outputting anything after rendering!

Resources