{"action":"created","issue":{"url":"https://api.github.com/repos/amir20/phantomjs-node/issues/414","repository_url":"https://api.github.com/repos/amir20/phantomjs-node","labels_url":"https://api.github.com/repos/amir20/phantomjs-node/issues/414/labels{/name}","comments_url":"https://api.github.com/repos/amir20/phantomjs-node/issues/414/comments","events_url":"https://api.github.com/repos/amir20/phantomjs-node/issues/414/events","html_url":"https://github.com/amir20/phantomjs-node/issues/414","id":141317513,"number":414,"title":"Incorrect page.evaluate behavior","user":{"login":"BPkazemi","id":1800902,"avatar_url":"https://avatars.githubusercontent.com/u/1800902?v=3","gravatar_id":"","url":"https://api.github.com/users/BPkazemi","html_url":"https://github.com/BPkazemi","followers_url":"https://api.github.com/users/BPkazemi/followers","following_url":"https://api.github.com/users/BPkazemi/following{/other_user}","gists_url":"https://api.github.com/users/BPkazemi/gists{/gist_id}","starred_url":"https://api.github.com/users/BPkazemi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BPkazemi/subscriptions","organizations_url":"https://api.github.com/users/BPkazemi/orgs","repos_url":"https://api.github.com/users/BPkazemi/repos","events_url":"https://api.github.com/users/BPkazemi/events{/privacy}","received_events_url":"https://api.github.com/users/BPkazemi/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-16T15:56:37Z","updated_at":"2016-03-16T16:04:22Z","closed_at":"2016-03-16T16:04:22Z","body":"### Expected behavior\r\n\r\n``page.evaluate`` should return the contents of the selector to the promise handler.\r\n\r\n### Actual behavior\r\n\r\nAny use of a selector causes evaluate to \"hang\". The handler is never called.\r\n\r\n### Steps to reproduce the behavior\r\nRunning the below prints \"response: true\", so the DOM element is being found.\r\n```\r\nvar phantom = require('phantom');\r\n\r\nphantom.create().then(function(ph) {\r\n    ph.createPage().then(function(page) {\r\n        page.open('http://stackoverflow.com').then(function(status) {\r\n            console.log('page opened.');\r\n            if (status == 'success') {\r\n                page.evaluate(function() {\r\n                    return document.querySelector('div#footer') ? true : false;\r\n                }).then(function(fulfilled) {\r\n                    console.log('response:', fulfilled);  // \"response: true\"\r\n                    page.close();\r\n                    ph.exit();\r\n                }, function(reject) {\r\n                    console.log('rejected:', reject);\r\n                });\r\n            }\r\n        });\r\n    });\r\n});\r\n```\r\n\r\nHowever, trying to return the element itself fails:\r\n```\r\npage.evaluate(function() {\r\n    return document.querySelector('div#footer');\r\n}).then(function(fulfilled) {\r\n    console.log('response:', fulfilled);  // Never called\r\n    page.close();\r\n    ph.exit();\r\n}, function(reject) {\r\n    console.log('rejected:', reject);\r\n});\r\n```\r\n### Environment\r\n\r\n- OS: OS X Yosemite 10.10.5\r\n- Node version (`node -v`): 5.4.0\r\n- package version: 2.0.6\r\n- Fresh install from ``npm install phantom``\r\n\r\n``page.evaluate`` is an oft-used command, so I'm surprised to see this failing. Am I missing something here? "},"comment":{"url":"https://api.github.com/repos/amir20/phantomjs-node/issues/comments/197399360","html_url":"https://github.com/amir20/phantomjs-node/issues/414#issuecomment-197399360","issue_url":"https://api.github.com/repos/amir20/phantomjs-node/issues/414","id":197399360,"user":{"login":"amir20","id":260667,"avatar_url":"https://avatars.githubusercontent.com/u/260667?v=3","gravatar_id":"","url":"https://api.github.com/users/amir20","html_url":"https://github.com/amir20","followers_url":"https://api.github.com/users/amir20/followers","following_url":"https://api.github.com/users/amir20/following{/other_user}","gists_url":"https://api.github.com/users/amir20/gists{/gist_id}","starred_url":"https://api.github.com/users/amir20/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amir20/subscriptions","organizations_url":"https://api.github.com/users/amir20/orgs","repos_url":"https://api.github.com/users/amir20/repos","events_url":"https://api.github.com/users/amir20/events{/privacy}","received_events_url":"https://api.github.com/users/amir20/received_events","type":"User","site_admin":false},"created_at":"2016-03-16T16:04:22Z","updated_at":"2016-03-16T16:04:22Z","body":"The return object is serialized to JSON and returned to node. `document.querySelector('div#footer')` doesn't make sense to be serialized so it won't work. You have to return simple objects not a DOM object. "}}