{"id":19179279,"url":"https://github.com/royalgarter/phantom-helper","last_synced_at":"2025-07-21T10:32:06.191Z","repository":{"id":22342540,"uuid":"25678290","full_name":"royalgarter/phantom-helper","owner":"royalgarter","description":"Helper for PhantomJS with Node.js with plenty of handy functions","archived":false,"fork":false,"pushed_at":"2017-06-01T04:27:36.000Z","size":32,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-10T21:49:43.014Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/phantom-helper","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/royalgarter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-24T08:12:54.000Z","updated_at":"2018-09-28T17:33:36.000Z","dependencies_parsed_at":"2022-07-25T09:02:09.601Z","dependency_job_id":null,"html_url":"https://github.com/royalgarter/phantom-helper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/royalgarter/phantom-helper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royalgarter%2Fphantom-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royalgarter%2Fphantom-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royalgarter%2Fphantom-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royalgarter%2Fphantom-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/royalgarter","download_url":"https://codeload.github.com/royalgarter/phantom-helper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/royalgarter%2Fphantom-helper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264740310,"owners_count":23656768,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T10:42:38.692Z","updated_at":"2025-07-21T10:32:06.162Z","avatar_url":"https://github.com/royalgarter.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\nRewrite most static functions for below purposes\n\n* Compatile with another sync libraries (with callback is the last argument)\n* Add some handy function to wait for page loaded with ajax\n* Render both light-weight html and image for Debugging\n\n\n# Prerequires: \n\n* Take a look at: https://github.com/baudehlo/node-phantom-simple (what we based on)\n* Take a look at: http://phantomjs.org/api/command-line.html (the original one)\n\n\n# Basic sample\n\n* With Callback Hell\n\n```\nvar _ph = require('./PhantomHelper');\n\n_ph.createDefaultPage('http://www.google.com', function (err, page) {\n\t_ph.fill(page, '#gbqfq', 0, 'phantom-helper', function (err, result) {\n\t\t_ph.click(page, '#gbqfba', 0, 1, function (err, result) { \n\t\t\t_ph.render(page, 'res.jpg', function (err, result) { \n\t\t\t\tpage.close();\n\t\t\t});\n\t\t});\n\t});\n});\n\n```\n\n* Without Callback Hell using wait.for\n\n```\nvar _w = require('wait.for');\nvar _ph = require('./PhantomHelper');\n\nvar run = function (page) {\n\t_w.for(_ph.fill, page, '#gbqfq', 0, 'phantom-helper');\n\t_w.for(_ph.click, page, '#gbqfba', 0, 1);\n\t_w.for(_ph.render, page, 'res.jpg');\n\n\t_w.for(page.close);\n}\n\n_ph.createDefaultPage('http://www.google.com', function (err, page) {\n\t_w.launchFiber(run, page);\n});\n\n```\n\n# Functions\n\n### Create page (phantom instance) with an url\n\n```javascript\nPhantomHelper.createDefaultPage = function(startURL, callback) {}\n\nPhantomHelper.createPage = function(phantomHelperCfg, startURL, callback) {}\n```\n\n### Configuration\n\nphantomOpt.parameters: is exactly the same as PhantomJs configure without '--'\nSee more here: http://phantomjs.org/api/command-line.html\n\n```javascript\n{   \n\t\"phantomOpt\" : {\t\t\n\t\t\"parameters\": {\n\t\t\t\"ignore-ssl-errors\": \"yes\",\n\t\t\t\"load-images\": \"no\",\n\t\t\t\"disk-cache\": \"yes\",\n\t\t\t\"max-disk-cache-size\": 10000,\n\t\t\t\"proxy-type\": \"none\"\n\t\t},\n\t\t\"noWait\": 0,     // not supported yet, leave as default\n\t\t\"multiPage\": 0   // not supported yet, leave as default\n\t},\n\t\"viewportSize\" : { \"width\": 1360, \"height\": 900 },\n\t\"timeOutMillis\" : 1000, // iterator timeout to check AJAX resources\n\t\"maxTimeOutMillis\" : 60000, // max timeout to check AJAX resources\n\t\"maxTryFinishRes\" : 3, // check the resource available n times to make sure AJAX loaded\n\t\"timeInterval\" : 300, // delay between each iterator check\n\t\"isDebugRender\" : 1, // render image and html\n\t\"isMiniRender\" : 1, // remove JS code in HTML render\n\t\"isDebug\" : 1 // for more console log to debugging\n}\n```\n\n\n### Render a page with both html content and image (for debugging)\n\n```javascript\nPhantomHelper.render = function(page, filepath, fnCallback, isForceRender) {}\n```\n\n### Execute inject function to phantom\nIf you want to pass by the input arguments for fnInject, they should placed right before the last callback function\n\n```javascript\n// execute inject function and wait for any AJAX\nPhantomHelper.doWait = function(page, fnInject, fnCallback) {}\n\n// execute inject function and wait for any condition function\nPhantomHelper.doWaitCond = function(page, fnInject, ifn_Condition, callback) {}\n\n// wait for any AJAX then execute inject function\nPhantomHelper.waitDo = function(page, fnInject, fnCallback) {}\n\n// wait for any condition function then execute inject function\nPhantomHelper.waitDoCond = function(page, fnInject, ifn_Condition, callback) {}\n\n// execute inject function without waiting\nPhantomHelper.do = function(page, fnInject, callback) {}\n```\n\n### Some handy overwrite function with support index when using document.querySelectorAll() in selector\n\n\n```javascript\nPhantomHelper.fill = function(page, query, index, value, fnCallback) {}\n\nPhantomHelper.click = function(page, query, index, isWait, fnCallback) {}\n\nPhantomHelper.clickEx = function(page, query, isWait, fnCallback) {}\n// Support jQuery like selector with :eq(\u003cindex\u003e) to clarify index of DOM\n\nPhantomHelper.clickNaEx = function(page, query, options/*(default null)*/, isWait, fnCallback) {}\n// Apply the native click (click at XY coordinate based on viewportSize). See more at: http://phantomjs.org/api/webpage/method/send-event.html\n\nPhantomHelper.fillEx = function(page, query, value, fnCallback) {}\n\nPhantomHelper.upload = function(page, query, filepath, fnCallback) {}\n\n```\n\n### Get value DOM value from page, queries should follow the below format\n\n* Array: [queryStr1, queryStr2, ... queryStrN]\n* Single string: queryStr\n\n Result is Hash object with queries as keys and their results as values\n\n Each query should be formatted as 'selector\u003e\u003eindex\u003e\u003eattribute'.\n attribute is DOM attribute or 'text' for innerText and 'html' for innerHTML\n\n * Example:\n    queries = '.a div span\u003e\u003e0\u003e\u003etext';\n    queries = ['.a div span\u003e\u003e0\u003e\u003etext', '.tr div a\u003e\u003e0\u003e\u003ehtml'];\n\n```javascript\nPhantomHelper.getVal = function(page, queries, fnCallback) {}\n```\n\n### Waiting functions that wait for AJAX loaded or specified condition\n* All the timeout could be ommitted to use the default value from config\n\n```javascript\nPhantomHelper.waitForCondition = function(page, ifn_Condition, timeoutInterval, maxTimeOutMillis, callback) {}\n\nPhantomHelper.waitPageLoaded = function (page, timeOutMillis, maxTimeOutMillis, callback) {}\n```\n\n### Super handy waiting function\n\n\n```javascript\nPhantomHelper.wait = function(page, condition, callback) {}\n\n/* \ncondition could be:\n* number: wait in ms\n* string: selector string, wait for that element existed\n* array: array of selector strings, wait for all elements existed\n* function: wait for that condition function return true\n\nIf condition is omitted (page, callback), default waitPageLoaded will be called\n\n*/\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froyalgarter%2Fphantom-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froyalgarter%2Fphantom-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froyalgarter%2Fphantom-helper/lists"}