{"id":19326862,"url":"https://github.com/panosoft/phantom-promise","last_synced_at":"2025-02-24T06:22:00.775Z","repository":{"id":35858250,"uuid":"40143201","full_name":"panosoft/phantom-promise","owner":"panosoft","description":"A PhantomJS bridge with a promise based api.","archived":false,"fork":false,"pushed_at":"2016-01-05T21:36:07.000Z","size":14,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-23T04:27:29.083Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/panosoft.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":"2015-08-03T19:11:37.000Z","updated_at":"2017-03-24T00:15:31.000Z","dependencies_parsed_at":"2022-08-17T22:55:10.568Z","dependency_job_id":null,"html_url":"https://github.com/panosoft/phantom-promise","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panosoft%2Fphantom-promise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panosoft%2Fphantom-promise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panosoft%2Fphantom-promise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panosoft%2Fphantom-promise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/panosoft","download_url":"https://codeload.github.com/panosoft/phantom-promise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240427651,"owners_count":19799535,"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-10T02:15:08.372Z","updated_at":"2025-02-24T06:22:00.749Z","avatar_url":"https://github.com/panosoft.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phantom-promise\n\nA [PhantomJS](http://phantomjs.org/) bridge with a promise based api.\n\n[![npm version](https://img.shields.io/npm/v/phantom-promise.svg)](https://www.npmjs.com/package/phantom-promise)\n[![Travis](https://img.shields.io/travis/panosoft/phantom-promise.svg)](https://travis-ci.org/panosoft/phantom-promise)\n\n## Installation\n\n```sh\nnpm install phantom-promise\n```\n\n## Usage\n\n```js\nvar Phantom = require('phantom-promise');\n\nvar phantom = Phantom.create();\nphantom.initialize()\n  .then(() =\u003e phantom.createPage())\n  .then((page) =\u003e {\n    var pageFunction = function () {\n      var result = 'Hello from Phantom.';\n      window.callPhantom(result);\n    };\n    return page.evaluate(pageFunction);\n  })\n  .then((result) =\u003e {\n    console.log(result); //=\u003e Hello from Phantom.\n    phantom.shutdown();\n  });\n```\n\n## API\n\n__Phantom__\n\n- [`create`](#create)\n- [`createPage`](#createPage)\n- [`initialize`](#initialize)\n- [`shutdown`](#shutdown)\n\n__Page__\n\n- [`close`](#close)\n- [`evaluate`](#evaluate)\n- [`get`](#get)\n- [`injectJs`](#injectJs)\n- [`set`](#set)\n\n---\n\n### Phantom\n\n\u003ca name=\"create\"\u003e\u003c/a\u003e\n#### create ( )\n\nReturns an instance of `Phantom`.\n\n__Example__\n\n```js\nvar Phantom = require('phantom-promise');\n\nvar phantom = Phantom.create();\n```\n\n---\n\n\u003ca name=\"createPage\"\u003e\u003c/a\u003e\n#### createPage ( )\n\nCreates a [Web Page](http://phantomjs.org/api/webpage/) in PhantomJs. Returns a `Promise` that is fulfilled with an instance of `Page`.\n\n__Example__\n\n```js\nphantom.createPage()\n  .then((page) =\u003e {\n    // ...\n  })\n```\n\n---\n\n\u003ca name=\"initialize\"\u003e\u003c/a\u003e\n#### initialize ( )\n\nInitializes the `Phantom` instance. Returns a `Promise` that is fulfilled once the initialization is complete.\n\nThis must be called before the instance can be used.\n\n__Example__\n\n```js\nphantom.initialize()\n  .then(() =\u003e {\n    // ...\n  });\n```\n\n---\n\n\u003ca name=\"shutdown\"\u003e\u003c/a\u003e\n#### shutdown ( )\n\nShuts down the phantom instance. Once this has been called, the instance is no longer operable unless it is re-initialized.\n\n__Example__\n\n```js\nphantom.shutdown();\n```\n\n---\n\n### Page\n\n\u003ca name=\"close\"\u003e\u003c/a\u003e\n#### close ( )\n\nCloses the page. Once this has been called, the page instance can no longer be used.\n\n__Example__\n\n```js\npage.close();\n```\n\n---\n\n\u003ca name=\"evaluate\"\u003e\u003c/a\u003e\n#### evaluate ( fn [,arg] )\n\nEvaluates a function on the page. Returns a `Promise` that is fulfilled with the return value of the function.\n\n__Arguments__\n\n- `fn` - The function to evaluate on the page. This function must call `window.callPhantom(result)` in order to return.\n- `arg` - An argument to evaluate `fn` with. This argument must be JSON-serializable (i.e. Closures, functions, DOM nodes, etc. will not work!).\n\n__Example__\n\n```js\nvar pageFunction = function (arg) {\n  window.callPhantom(arg);\n};\n\nvar arg = 'Hello from Phantom.';\npage.evaluate(pageFunction, arg)\n  .then((result) =\u003e {\n    console.log(result); //=\u003e 'Hello from Phantom.'\n  });\n```\n\n---\n\n\u003ca name=\"get\"\u003e\u003c/a\u003e\n#### get ( property )\n\nReturns a Promise that is fulfilled with the requested page property.\n\n__Arguments__\n\n- `property` - A string determining the property to return.\n\n__Example__\n\n```js\npage.get('viewportSize')\n  .then((viewportSize) =\u003e {\n    // ...\n  });\n```\n\n---\n\n\u003ca name=\"injectJs\"\u003e\u003c/a\u003e\n#### injectJs ( paths )\n\nInjects external scripts into the page. The scripts are loaded in the order they are supplied so that dependencies can be met.\n\n__Arguments__\n\n- `paths` - A path or an array of paths to the script files to be injected.\n\n__Example__\n\n```js\npage.injectJs('path/to/external/script.js');\n```\n\n---\n\n\u003ca name=\"set\"\u003e\u003c/a\u003e\n#### set ( property , value )\n\nSets a page property. Returns a promise that is fulfilled with the result.\n\n__Arguments__\n\n- `property` - A string determining the property to set.\n- `value` - The value to apply.\n\n__Example__\n\n```js\npage.set('viewportSize', {height: 768, width: 1024});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanosoft%2Fphantom-promise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpanosoft%2Fphantom-promise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanosoft%2Fphantom-promise/lists"}