{"id":20767003,"url":"https://github.com/binded/phantom-pool","last_synced_at":"2025-08-22T01:32:38.546Z","repository":{"id":57157366,"uuid":"75018264","full_name":"binded/phantom-pool","owner":"binded","description":"PhantomJS resource pool based on generic-pool ","archived":false,"fork":false,"pushed_at":"2019-07-17T01:56:50.000Z","size":15,"stargazers_count":106,"open_issues_count":6,"forks_count":65,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-12-13T06:36:03.702Z","etag":null,"topics":["nodejs","npm","phantomjs","pool","resource-pool"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binded.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-28T22:03:10.000Z","updated_at":"2024-11-30T05:44:25.000Z","dependencies_parsed_at":"2022-09-07T20:50:36.734Z","dependency_job_id":null,"html_url":"https://github.com/binded/phantom-pool","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fphantom-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fphantom-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fphantom-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fphantom-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binded","download_url":"https://codeload.github.com/binded/phantom-pool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230547678,"owners_count":18243227,"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":["nodejs","npm","phantomjs","pool","resource-pool"],"created_at":"2024-11-17T11:27:12.014Z","updated_at":"2024-12-20T07:06:58.571Z","avatar_url":"https://github.com/binded.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phantom-pool\n\n[![Build Status](https://travis-ci.org/binded/phantom-pool.svg?branch=master)](https://travis-ci.org/binded/phantom-pool)\n\nResource pool based on [generic-pool](https://github.com/coopernurse/node-pool) for [PhantomJS](https://github.com/amir20/phantomjs-node).\n\nCreating new phantom instances with `phantom.create()` can be slow. If\nyou are frequently creating new instances and destroying them, as a\nresult of HTTP requests for example, this module can help by keeping a\npool of phantom instances alive and making it easy to re-use them across\nrequests.\n\nHere's an artificial [benchmark](./test/benchmark.js) to illustrate:\n\n```\nStarting benchmark without pool\n\nnoPool-0: 786.829ms\nnoPool-1: 790.822ms\nnoPool-2: 795.150ms\nnoPool-3: 788.928ms\nnoPool-4: 793.788ms\nnoPool-5: 798.075ms\nnoPool-6: 813.130ms\nnoPool-7: 803.801ms\nnoPool-8: 782.936ms\nnoPool-9: 805.630ms\n\nStarting benchmark with pool\n\npool-0: 48.160ms\npool-1: 98.966ms\npool-2: 89.573ms\npool-3: 99.057ms\npool-4: 101.970ms\npool-5: 102.967ms\npool-6: 102.938ms\npool-7: 99.359ms\npool-8: 101.972ms\npool-9: 103.309ms\n\nDone\n```\n\nUsing pool in this benchmark results in an average \u003e8x speed increase.\n\n## Install\n\n```bash\nnpm install --save phantom-pool\n```\n\nRequires Node v6+\n\n## Usage\n\nSee [./test](./test) directory for usage examples.\n\n```javascript\nconst createPhantomPool = require('phantom-pool')\n\n// Returns a generic-pool instance\nconst pool = createPhantomPool({\n  max: 10, // default\n  min: 2, // default\n  // how long a resource can stay idle in pool before being removed\n  idleTimeoutMillis: 30000, // default.\n  // maximum number of times an individual resource can be reused before being destroyed; set to 0 to disable\n  maxUses: 50, // default\n  // function to validate an instance prior to use; see https://github.com/coopernurse/node-pool#createpool\n  validator: () =\u003e Promise.resolve(true), // defaults to always resolving true\n  // validate resource before borrowing; required for `maxUses and `validator`\n  testOnBorrow: true, // default\n  // For all opts, see opts at https://github.com/coopernurse/node-pool#createpool\n  phantomArgs: [['--ignore-ssl-errors=true', '--disk-cache=true'], {\n    logLevel: 'debug',\n  }], // arguments passed to phantomjs-node directly, default is `[]`. For all opts, see https://github.com/amir20/phantomjs-node#phantom-object-api\n})\n\n// Automatically acquires a phantom instance and releases it back to the\n// pool when the function resolves or throws\npool.use(async (instance) =\u003e {\n  const page = await instance.createPage()\n  const status = await page.open('http://google.com', { operation: 'GET' })\n  if (status !== 'success') {\n    throw new Error('cannot open google.com')\n  }\n  const content = await page.property('content')\n  return content\n}).then((content) =\u003e {\n  console.log(content)\n})\n\n// Destroying the pool:\npool.drain().then(() =\u003e pool.clear())\n\n// For more API doc, see https://github.com/coopernurse/node-pool#generic-pool\n```\n\n## Security\n\nWhen using phantom-pool, you should be aware that the phantom instance\nyou are getting might not be in a completely clean state. It could have\nbrowser history, cookies or other persistent data from a previous use.\n\nIf that is an issue for you, make sure you clean up any sensitive data\non the phantom instance before returning it to the pool.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinded%2Fphantom-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinded%2Fphantom-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinded%2Fphantom-pool/lists"}