{"id":16531302,"url":"https://github.com/bjrmatos/chrome-page-eval","last_synced_at":"2025-03-23T13:32:31.022Z","repository":{"id":72388802,"uuid":"123478373","full_name":"bjrmatos/chrome-page-eval","owner":"bjrmatos","description":"Evaluate a script function on a page with Chrome 🔮","archived":false,"fork":false,"pushed_at":"2024-03-14T22:21:16.000Z","size":49,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-15T01:57:04.421Z","etag":null,"topics":["chrome","eval","puppeteer"],"latest_commit_sha":null,"homepage":null,"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/bjrmatos.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-01T18:51:09.000Z","updated_at":"2024-06-18T19:51:52.171Z","dependencies_parsed_at":"2024-06-18T19:51:42.184Z","dependency_job_id":null,"html_url":"https://github.com/bjrmatos/chrome-page-eval","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjrmatos%2Fchrome-page-eval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjrmatos%2Fchrome-page-eval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjrmatos%2Fchrome-page-eval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjrmatos%2Fchrome-page-eval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bjrmatos","download_url":"https://codeload.github.com/bjrmatos/chrome-page-eval/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245108297,"owners_count":20562021,"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":["chrome","eval","puppeteer"],"created_at":"2024-10-11T18:08:28.186Z","updated_at":"2025-03-23T13:32:30.685Z","avatar_url":"https://github.com/bjrmatos.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chrome-page-eval\n[![NPM Version](http://img.shields.io/npm/v/chrome-page-eval.svg?style=flat-square)](https://npmjs.com/package/chrome-page-eval)\n[![License](http://img.shields.io/npm/l/chrome-page-eval.svg?style=flat-square)](http://opensource.org/licenses/MIT)\n[![Build Status](https://travis-ci.org/bjrmatos/chrome-page-eval.png?branch=master)](https://travis-ci.org/bjrmatos/chrome-page-eval)\n\n\u003e **Evaluate a script function on a page with Chrome**\n\nThis module let you evaluate a script function on a page using Chrome (controlled with [puppeteer](https://github.com/GoogleChrome/puppeteer)) and get the return value of the evaluation in node.\n\n## Usage\n```html\n\u003c!-- sample.html --\u003e\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n  \u003cmeta charset=\"UTF-8\"\u003e\n  \u003ctitle\u003eTest page\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003cdiv class=\"content\"\u003e1\u003c/div\u003e\n  \u003cdiv class=\"content\"\u003e2\u003c/div\u003e\n  \u003cdiv class=\"content\"\u003e3\u003c/div\u003e\n  \u003cdiv class=\"content\"\u003e4\u003c/div\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n```js\nconst puppeteer = require('puppeteer')\nconst chromePageEval = require('chrome-page-eval')\nconst chromeEval = chromePageEval({ puppeteer })\n\n(async () =\u003e {\n  try {\n    const result = await chromeEval({\n      html: '/path/to/sample.html',\n      scriptFn: `\n        function () {\n          let title = document.title\n\n          let content = Array.from(document.querySelectorAll('.content'), (node) =\u003e {\n            return node.textContent\n          })\n\n          return {\n            title,\n            content\n          }\n        }\n      `\n    })\n\n    console.log(result.title) // -\u003e Test page\n    console.log(result.content) // -\u003e [1, 2, 3, 4]\n  } catch (e) {\n    console.error('Error while trying to evaluate script:', e)\n  }\n})()\n```\n\n## Constructor options\n\n```js\nconst chromePageEval = require('chrome-page-eval')\nconst chromeEval = chromePageEval({ /*[constructor options here]*/ })\n```\n\n- `puppeteer` **[required]** - the exported module from [puppeteer](https://github.com/GoogleChrome/puppeteer) that your app is going to use\n- properties with [any of the launch options supported by puppeteer](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions)\n\n## Evaluate options\n\n```js\nconst puppeteer = require('puppeteer')\nconst chromePageEval = require('chrome-page-eval')\nconst chromeEval = chromePageEval({ puppeteer })\n\n(async () =\u003e {\n  const result = await chromeEval({ /*[evaluate options here]*/ })\n})()\n```\n\n- `html` **string** **[required]** - the path to the html file to load in a Chrome page\n- `scriptFn` **string** **[required]** - the script to evaluate in the Chrome page. the script must be a function that returns a value. ex: `scriptFn: 'function () { return 1 + 2}'`\n- `viewport` **object** - object with [any of the viewport options supported by puppeteer](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagesetviewportviewport)\n- `args` **array** - a list of custom arguments to pass to the `scriptFn` function. ex: `args: [1, 2]` and with `scriptFn: function (a, b) { return a + b}'` will produce `3` as result\n- `styles` **array\u003cstring\u003e** - array of css strings to insert at the beginning of page's head element. ex: `styles: ['* { font-family: 'Calibri'; font-size: 16px; }']`\n- `waitForJS` **boolean** - when `true` the `scriptFn` won't be executed until the variable specified in `waitForJSVarName` option is set to true in page's javscript. defaults to `false`\n- `waitForJSVarName` **string** - name of the variable that will be used as trigger of `scriptFn`. defaults to `\"CHROME_PAGE_EVAL_READY\"`\n- `waitUntil` **string** - a value that specifies when a page is considered to be loaded, [for the list of all possible values and its meanings see `waitUntil` option in puppeteer docs](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagegotourl-options). defaults to the the default value of puppeteer\n- `timeout` **number** - time in ms to wait for the script evaluation to complete, when the timeout is reached the evaluation is cancelled. defaults to `30000`\n\n## Requirements\n\n- Install puppeteer \u003e= 1.0.0 with `npm install puppeteer --save` in your project and pass it to `chrome-page-eval` constructor function.\n\n## Caveats\n\n- What you return in your script function (`scriptFn` option) must be a [serializable value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description) in order to receive it properly, if a non serializable value is returned you will get `undefined` as the result.\n\n## Debugging\n\n- To get more information (internal debugging logs of the module) about what's happening during the evaluation on the page start your app in this way: `DEBUG=chrome-page-eval* node [your-entry-file-here].js` (on Windows use `set DEBUG=chrome-page-eval* \u0026\u0026 node [your-entry-file-here].js`). This will print out to the console some additional information about what's going on.\n\n- To see the Chrome instance created (the visible chrome window) run your app with the `CHROME_PAGE_EVAL_DEBUGGING` env var: `CHROME_PAGE_EVAL_DEBUGGING=true node [your-entry-file-here].js` (on Windows use `set CHROME_PAGE_EVAL_DEBUGGING=true \u0026\u0026 node [your-entry-file-here].js`).\n\n## License\nSee [license](https://github.com/bjrmatos/chrome-page-eval/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjrmatos%2Fchrome-page-eval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbjrmatos%2Fchrome-page-eval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjrmatos%2Fchrome-page-eval/lists"}