{"action":"created","issue":{"url":"https://api.github.com/repos/atom/electron/issues/4262","labels_url":"https://api.github.com/repos/atom/electron/issues/4262/labels{/name}","comments_url":"https://api.github.com/repos/atom/electron/issues/4262/comments","events_url":"https://api.github.com/repos/atom/electron/issues/4262/events","html_url":"https://github.com/atom/electron/issues/4262","id":129563321,"number":4262,"title":"using Electron instead of phantomjs","user":{"login":"lasryaric","id":358965,"avatar_url":"https://avatars.githubusercontent.com/u/358965?v=3","gravatar_id":"","url":"https://api.github.com/users/lasryaric","html_url":"https://github.com/lasryaric","followers_url":"https://api.github.com/users/lasryaric/followers","following_url":"https://api.github.com/users/lasryaric/following{/other_user}","gists_url":"https://api.github.com/users/lasryaric/gists{/gist_id}","starred_url":"https://api.github.com/users/lasryaric/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lasryaric/subscriptions","organizations_url":"https://api.github.com/users/lasryaric/orgs","repos_url":"https://api.github.com/users/lasryaric/repos","events_url":"https://api.github.com/users/lasryaric/events{/privacy}","received_events_url":"https://api.github.com/users/lasryaric/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/atom/electron/labels/question","name":"question","color":"c7def8"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-28T20:03:00Z","updated_at":"2016-01-28T23:49:23Z","closed_at":"2016-01-28T23:49:23Z","body":"I see in the doc [electron vs nw.js](https://github.com/atom/electron/blob/master/docs/development/atom-shell-vs-node-webkit.md) that Electron can be a replacement of Phantomjs:\r\n>  Electron's APIs are lower level so you can use it for browser testing in place of PhantomJS.\r\n\r\n\r\nI am writing a desktop application that needs to go browse a few website to collect some data (PDF bills).\r\nI tried 2 things in order to automate a BrowserWindow instance and have it navigate the website(s) by inputing the credentials, clicking on link etc, but I quickly met blockers.\r\n\r\n# solution 1\r\n\r\nuse a preload script and communicate via ipcMain messages. The preload script handle the message and click on the buttons and inputs the data in the input fields via javascript.\r\n\r\n**The problem is that the preload code is not available after navigating from one page to another.**\r\n\r\n# solution 2\r\nusing BrowserWindow.webContents.executeJavascript(\"code\") I send the code to click and input the data but in order to get a feedback from the browser, I am using:\r\n\r\n```javascript\r\nfunction clientClick(cssSelector) {\r\n\tconst ipcRenderer = require('electron').ipcRenderer;\r\n\t\r\n\tvar domElemement = document.querySelectorAll(cssSelector)\r\n\r\n\tconsole.log('clientClick: ', cssSelector)\r\n\tif (!domElemement || domElemement.length == 0) {\r\n\t\tcallback(new Error(\"dom element not found for css selector: \"+ cssSelector));\r\n\r\n\t\treturn ;\r\n\t}\r\n\r\n\tdomElemement[0].click();\r\n\t\r\n\tipcRenderer.send('doneExecuting');\r\n\t\r\n}\r\n```\r\n\r\non `github.com` for example, the line  `const ipcRenderer = require('electron').ipcRenderer;` throws an error because Github has its own `require()` function exposed in the browser.\r\n\r\nHere is the error thrown:\r\n```\r\nUncaught Error: Could not find module electronn @ frameworks-9ee55ceaf87fc34dc86334249fef6cbece88e815478e0fbe81642d57ed0fff89.js:1clientClick @ VM102:2(anonymous function) @ VM102:17electron.ipcRenderer.on @ /Users/ariclasry/dev/hellobill/electron-quick-start/node_modules/electron-prebuilt/dist/Electron.ap…:45emitThree @ events.js:97emit @ events.js:175\r\n```\r\n\r\n**What is the best solution to use Electron as PhantomJS?** \r\n\r\nI know that nightmarejs is doing something similar so I will start looking at the source code right now."},"comment":{"url":"https://api.github.com/repos/atom/electron/issues/comments/176485917","html_url":"https://github.com/atom/electron/issues/4262#issuecomment-176485917","issue_url":"https://api.github.com/repos/atom/electron/issues/4262","id":176485917,"user":{"login":"jlord","id":1305617,"avatar_url":"https://avatars.githubusercontent.com/u/1305617?v=3","gravatar_id":"","url":"https://api.github.com/users/jlord","html_url":"https://github.com/jlord","followers_url":"https://api.github.com/users/jlord/followers","following_url":"https://api.github.com/users/jlord/following{/other_user}","gists_url":"https://api.github.com/users/jlord/gists{/gist_id}","starred_url":"https://api.github.com/users/jlord/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlord/subscriptions","organizations_url":"https://api.github.com/users/jlord/orgs","repos_url":"https://api.github.com/users/jlord/repos","events_url":"https://api.github.com/users/jlord/events{/privacy}","received_events_url":"https://api.github.com/users/jlord/received_events","type":"User","site_admin":true},"created_at":"2016-01-28T23:49:23Z","updated_at":"2016-01-28T23:49:23Z","body":"@lasryaric Electron isn't a direct replacement of PhantomJS but can be used to build something similar to that. I'll clear up that documentation :soon: \r\n\r\nLooking at others like nightmarejs will hopefully get you on the right path. You might also find [maxogden/electron-microscope](https://github.com/maxogden/electron-microscope) useful :microscope: "}}