{"id":13468903,"url":"https://github.com/prerender/prerender","last_synced_at":"2025-10-20T11:32:58.221Z","repository":{"id":10834298,"uuid":"13112745","full_name":"prerender/prerender","owner":"prerender","description":"Node server that uses Headless Chrome to render a javascript-rendered page as HTML. To be used in conjunction with prerender middleware.","archived":false,"fork":false,"pushed_at":"2024-09-12T08:57:05.000Z","size":847,"stargazers_count":6513,"open_issues_count":110,"forks_count":933,"subscribers_count":107,"default_branch":"master","last_synced_at":"2025-05-05T19:17:16.088Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prerender.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2013-09-26T04:13:55.000Z","updated_at":"2025-04-30T16:57:26.000Z","dependencies_parsed_at":"2023-01-13T16:11:16.183Z","dependency_job_id":"27b25147-4a20-496b-8804-caf4b6936383","html_url":"https://github.com/prerender/prerender","commit_stats":{"total_commits":580,"total_committers":76,"mean_commits":7.631578947368421,"dds":0.6396551724137931,"last_synced_commit":"478fa6d0a5196ea29c88c69e64e72eb5507b6d2c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prerender%2Fprerender","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prerender%2Fprerender/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prerender%2Fprerender/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prerender%2Fprerender/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prerender","download_url":"https://codeload.github.com/prerender/prerender/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253765214,"owners_count":21960690,"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-07-31T15:01:21.594Z","updated_at":"2025-10-20T11:32:58.115Z","avatar_url":"https://github.com/prerender.png","language":"JavaScript","readme":"# Prerender\n\nPrerender is a node server that uses Headless Chrome to render HTML, screenshots, PDFs, and HAR files out of any web page. The Prerender server listens for an http request, takes the URL and loads it in Headless Chrome, waits for the page to finish loading by waiting for the network to be idle, and then returns your content.\n\n##### The quickest way to run your own prerender server:\n\n```bash\n$ npm install prerender\n```\n\n##### server.js\n\n```js\nconst prerender = require('prerender');\nconst server = prerender();\nserver.start();\n```\n\n##### test it:\n\n```bash\ncurl http://localhost:3000/render?url=https://www.example.com/\n```\n\n## Use Cases\n\nThe Prerender server can be used in conjunction with [our Prerender.io middleware](#middleware) in order to serve the prerendered HTML of your javascript website to search engines (Google, Bing, etc) and social networks (Facebook, Twitter, etc) for SEO. We run the Prerender server at scale for SEO needs at [https://prerender.io/](https://prerender.io/).\n\nThe Prerender server can be used on its own to crawl any web page and pull down the content for your own parsing needs. We host the Prerender server for your own crawling needs at [https://prerender.com/](https://prerender.com/).\n\nPrerender differs from Google Puppeteer in that Prerender is a web server that takes in URLs and loads them in parallel in a new tab in Headless Chrome. Puppeteer is an API for interacting with Chrome, but you still have to write that interaction yourself. With Prerender, you don't have to write any code to launch Chrome, load pages, wait for the page to load, or pull the content off of the page. The Prerender server handles all of that for you so you can focus on more important things!\n\nBelow you will find documentation for our Prerender.io service (website SEO) and our Prerender.com service (web crawling).\n\n[Click here to jump to Prerender.io documentation](#prerenderio)\n\n[Click here to jump to Prerender.com documentation](#prerendercom)\n\n### \u003ca id='prerenderio'\u003e\u003c/a\u003e\n\n# Prerender.io\n\n###### For serving your prerendered HTML to crawlers for SEO\n\nPrerender solves SEO by serving prerendered HTML to Google and other search engines. It's easy:\n\n- Just install the appropriate middleware for your app (or check out the source code and build your own)\n- Make sure search engines have a way of discovering your pages (e.g. sitemap.xml and links from other parts of your site or from around the web)\n- That's it! Perfect SEO on javascript pages.\n\n### \u003ca id='middleware'\u003e\u003c/a\u003e\n\n## Middleware\n\nThis is a list of middleware available to use with the prerender service:\n\n#### Official middleware\n\n###### Javascript\n\n- [prerender-node](https://github.com/prerender/prerender-node) (Express)\n\n###### Ruby\n\n- [prerender_rails](https://github.com/prerender/prerender_rails) (Rails)\n\n###### Apache\n\n- [.htaccess](https://gist.github.com/thoop/8072354)\n\n###### Nginx\n\n- [nginx.conf](https://gist.github.com/thoop/8165802)\n\n#### Community middleware\n\n###### PHP\n\n- [zfr-prerender](https://github.com/zf-fr/zfr-prerender) (Zend Framework 2)\n- [YuccaPrerenderBundle](https://github.com/rjanot/YuccaPrerenderBundle) (Symfony 2)\n- [Laravel Prerender](https://github.com/JeroenNoten/Laravel-Prerender) (Laravel)\n\n###### Java\n\n- [prerender-java](https://github.com/greengerong/prerender-java)\n\n###### Go\n\n- [goprerender](https://github.com/tampajohn/goprerender)\n\n###### Grails\n\n- [grails-prerender](https://github.com/tuler/grails-prerender)\n\n###### Nginx\n\n- [Reverse Proxy Example](https://gist.github.com/Stanback/6998085)\n\n###### Apache\n\n- [.htaccess](https://gist.github.com/Stanback/7028309)\n\nRequest more middleware for a different framework in this [issue](https://github.com/prerender/prerender/issues/12).\n\n## How it works\n\nThis is a simple service that only takes a url and returns the rendered HTML (with all script tags removed).\n\nNote: you should proxy the request through your server (using middleware) so that any relative links to CSS/images/etc still work.\n\n`GET https://service.prerender.io/https://www.google.com`\n\n`GET https://service.prerender.io/https://www.google.com/search?q=angular`\n\n## Running locally\n\nIf you are trying to test Prerender with your website on localhost, you'll have to run the Prerender server locally so that Prerender can access your local dev website.\n\nIf you are running the prerender service locally. Make sure you set your middleware to point to your local Prerender server with:\n\n`export PRERENDER_SERVICE_URL=http://localhost:3000`\n\n    $ git clone https://github.com/prerender/prerender.git\n    $ cd prerender\n    $ npm install\n    $ node server.js\n\nPrerender will now be running on http://localhost:3000. If you wanted to start a web app that ran on say, http://localhost:8000, you can now visit the URL http://localhost:3000/http://localhost:8000 to see how your app would render in Prerender.\n\nTo test how your website will render through Prerender using the middleware, you'll want to visit the URL http://localhost:8000?_escaped_fragment_=\n\nThat should send a request to the Prerender server and display the prerendered page through your website. If you View Source of that page, you should see the HTML with all of the `\u003cscript\u003e` tags removed.\n\nKeep in mind you will see 504s for relative URLs when accessing http://localhost:3000/http://localhost:8000 because the actual domain on that request is your prerender server. This isn't really an issue because once you proxy that request through the middleware, then the domain will be your website and those requests won't be sent to the prerender server. For instance if you want to see your relative URLS working visit `http://localhost:8000?_escaped_fragment_=`\n\n# Customization\n\nYou can clone this repo and run `server.js` OR include prerender in your project with `npm install prerender --save` to create an express-like server with custom plugins.\n\n## Options\n\n### chromeLocation\n\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    chromeLocation: '/Applications/Google\\ Chrome\\ Canary.app/Contents/MacOS/Google\\ Chrome\\ Canary'\n});\n\nserver.start();\n```\n\nUses a chrome install at a certain location. Prerender does not download Chrome so you will want to make sure Chrome is installed on your server already. The Prerender server checks a few known locations for Chrome but this lets you override that.\n\n`Default: null`\n\n### logRequests\n\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    logRequests: true\n});\n\nserver.start();\n```\n\nCauses the Prerender server to print out every request made represented by a `+` and every response received represented by a `-`. Lets you analyze page load times.\n\n`Default: false`\n\n### captureConsoleLog\n\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    captureConsoleLog: true\n});\n\nserver.start();\n```\n\nPrerender server will store all console logs into `pageLoadInfo.logEntries` for further analytics.\n\n`Default: false`\n\n### pageDoneCheckInterval\n\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    pageDoneCheckInterval: 1000\n});\n\nserver.start();\n```\n\nNumber of milliseconds between the interval of checking whether the page is done loading or not. You can also set the environment variable of `PAGE_DONE_CHECK_INTERVAL` instead of passing in the `pageDoneCheckInterval` parameter.\n\n`Default: 500`\n\n### pageLoadTimeout\n\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    pageLoadTimeout: 20 * 1000\n});\n\nserver.start();\n```\n\nMaximum number of milliseconds to wait while downloading the page, waiting for all pending requests/ajax calls to complete before timing out and continuing on. Time out condition does not cause an error, it just returns the HTML on the page at that moment. You can also set the environment variable of `PAGE_LOAD_TIMEOUT` instead of passing in the `pageLoadTimeout` parameter.\n\n`Default: 20000`\n\n### waitAfterLastRequest\n\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    waitAfterLastRequest: 500\n});\n\nserver.start();\n```\n\nNumber of milliseconds to wait after the number of requests/ajax calls in flight reaches zero. HTML is pulled off of the page at this point. You can also set the environment variable of `WAIT_AFTER_LAST_REQUEST` instead of passing in the `waitAfterLastRequest` parameter.\n\n`Default: 500`\n\n### followRedirects\n\n```\nvar prerender = require('./lib');\n\nvar server = prerender({\n    followRedirects: false\n});\n\nserver.start();\n```\n\nWhether Chrome follows a redirect on the first request if a redirect is encountered. Normally, for SEO purposes, you do not want to follow redirects. Instead, you want the Prerender server to return the redirect to the crawlers so they can update their index. Don't set this to `true` unless you know what you are doing. You can also set the environment variable of `FOLLOW_REDIRECTS` instead of passing in the `followRedirects` parameter.\n\n`Default: false`\n\n## Plugins\n\nWe use a plugin system in the same way that Connect and Express use middleware. Our plugins are a little different and we don't want to confuse the prerender plugins with the [prerender middleware](#middleware), so we opted to call them \"plugins\".\n\nPlugins are in the `lib/plugins` directory, and add functionality to the prerender service.\n\nEach plugin can implement any of the plugin methods:\n\n#### `init()`\n\n#### `requestReceived(req, res, next)`\n\n#### `tabCreated(req, res, next)`\n\n#### `pageLoaded(req, res, next)`\n\n#### `beforeSend(req, res, next)`\n\n## Available plugins\n\nYou can use any of these plugins by modifying the `server.js` file\n\n### basicAuth\n\nIf you want to only allow access to your Prerender server from authorized parties, enable the basic auth plugin.\n\nYou will need to add the `BASIC_AUTH_USERNAME` and `BASIC_AUTH_PASSWORD` environment variables.\n\n```\nexport BASIC_AUTH_USERNAME=prerender\nexport BASIC_AUTH_PASSWORD=test\n```\n\nThen make sure to pass the basic authentication headers (password base64 encoded).\n\n```\ncurl -u prerender:wrong http://localhost:3000/http://example.com -\u003e 401\ncurl -u prerender:test http://localhost:3000/http://example.com -\u003e 200\n```\n\n### removeScriptTags\n\nWe remove script tags because we don't want any framework specific routing/rendering to happen on the rendered HTML once it's executed by the crawler. The crawlers may not execute javascript, but we'd rather be safe than have something get screwed up.\n\nFor example, if you rendered the HTML of an angular page but left the angular scripts in there, your browser would try to execute the angular routing and possibly end up clearing out the HTML of the page.\n\nThis plugin implements the `pageLoaded` function, so make sure any caching plugins run after this plugin is run to ensure you are caching pages with javascript removed.\n\n### httpHeaders\n\nIf your Javascript routing has a catch-all for things like 404's, you can tell the prerender service to serve a 404 to google instead of a 200. This way, google won't index your 404's.\n\nAdd these tags in the `\u003chead\u003e` of your page if you want to serve soft http headers. Note: Prerender will still send the HTML of the page. This just modifies the status code and headers being sent.\n\nExample: telling prerender to server this page as a 404\n\n```html\n\u003cmeta name=\"prerender-status-code\" content=\"404\" /\u003e\n```\n\nExample: telling prerender to serve this page as a 302 redirect\n\n```html\n\u003cmeta name=\"prerender-status-code\" content=\"302\" /\u003e\n\u003cmeta name=\"prerender-header\" content=\"Location: https://www.google.com\" /\u003e\n```\n\n### whitelist\n\nIf you only want to allow requests to a certain domain, use this plugin to cause a 404 for any other domains.\n\nYou can add the whitelisted domains to the plugin itself, or use the `ALLOWED_DOMAINS` environment variable.\n\n`export ALLOWED_DOMAINS=www.prerender.io,prerender.io`\n\n### blacklist\n\nIf you want to disallow requests to a certain domain, use this plugin to cause a 404 for the domains.\n\nYou can add the blacklisted domains to the plugin itself, or use the `BLACKLISTED_DOMAINS` environment variable.\n\n`export BLACKLISTED_DOMAINS=yahoo.com,www.google.com`\n\n### in-memory-cache\n\nCaches pages in memory. Available at [prerender-memory-cache](https://github.com/prerender/prerender-memory-cache)\n\n### s3-html-cache\n\nCaches pages in S3. Available at [coming soon](https://github.com/prerender/prerender)\n\n---\n\n### \u003ca id='prerendercom'\u003e\u003c/a\u003e\n\n# Prerender.com\n\n###### For doing your own web crawling\n\nWhen running your Prerender server in the web crawling context, we have a separate \"API\" for the server that is more complex to let you do different things like:\n\n- get HTML from a web page\n- get screenshots (viewport or full screen) from a web page\n- get PDFS from a web page\n- get HAR files from a web page\n- execute your own javascript and return json along with the HTML\n\nIf you make an http request to the `/render` endpoint, you can pass any of the following options. You can pass any of these options as query parameters on a GET request or as JSON properties on a POST request. We recommend using a POST request but we will display GET requests here for brevity. Click here to see [how to send the POST request](#getvspost).\n\nThese examples assume you have the server running locally on port 3000 but you can also use our hosted service at [https://prerender.com/](https://prerender.com/).\n\n#### url\n\nThe URL you want to load. Returns HTML by default.\n\n```\nhttp://localhost:3000/render?url=https://www.example.com/\n```\n\n#### renderType\n\nThe type of content you want to pull off the page.\n\n```\nhttp://localhost:3000/render?renderType=html\u0026url=https://www.example.com/\n```\n\nOptions are `html`, `jpeg`, `png`, `pdf`, `har`.\n\n#### userAgent\n\nSend your own custom user agent when Chrome loads the page.\n\n```\nhttp://localhost:3000/render?userAgent=ExampleCrawlerUserAgent\u0026url=https://www.example.com/\n```\n\n#### fullpage\n\nWhether you want your screenshot to be the entire height of the document or just the viewport.\n\n```\nhttp://localhost:3000/render?fullpage=true\u0026renderType=html\u0026url=https://www.example.com/\n```\n\nDon't include `fullpage` and we'll just screenshot the normal browser viewport. Include `fullpage=true` for a full page screenshot.\n\n#### width\n\nScreen width. Lets you emulate different screen sizes.\n\n```\nhttp://localhost:3000/render?width=990\u0026url=https://www.example.com/\n```\n\nDefault is `1440`.\n\n#### height\n\nScreen height. Lets you emulate different screen sizes.\n\n```\nhttp://localhost:3000/render?height=100\u0026url=https://www.example.com/\n```\n\nDefault is `718`.\n\n#### followRedirects\n\nBy default, we don't follow 301 redirects on the initial request so you can be alerted of any changes in URLs to update your crawling data. If you want us to follow redirects instead, you can pass this parameter.\n\n```\nhttp://localhost:3000/render?followRedirects=true\u0026url=https://www.example.com/\n```\n\nDefault is `false`.\n\n#### javascript\n\nExecute javascript to modify the page before we snapshot your content. If you set `window.prerenderData` to an object, we will pull the object off the page and return it to you. Great for parsing extra data from a page in javascript.\n\n```\nhttp://localhost:3000/render?javascript=window.prerenderData=window.angular.version\u0026url=https://www.example.com/\n```\n\nWhen using this parameter and `window.prerenderData`, the response from Prerender will look like:\n\n```\n{\n\tprerenderData: { example: 'data' },\n\tcontent: '\u003chtml\u003e\u003cbody\u003e\u003c/body\u003e\u003c/html\u003e'\n}\n```\n\nIf you don't set `window.prerenderData`, the response won't be JSON. The response will just be the normal HTML.\n\n### \u003ca id='getvspost'\u003e\u003c/a\u003e\n\n### Get vs Post\n\nYou can send all options as a query parameter on a GET request or as a JSON property on a POST request. We recommend using the POST request when possible to avoid any issues with URL encoding of GET request query strings. Here's a few pseudo examples:\n\n```\nPOST http://localhost:3000/render\n{\n\trenderType: 'html',\n\tjavascript: 'window.prerenderData = window.angular.version',\n\turl: 'https://www.example.com/'\n}\n```\n\n```\nPOST http://localhost:3000/render\n{\n\trenderType: 'jpeg',\n\tfullpage: 'true',\n\turl: 'https://www.example.com/'\n}\n```\n\nCheck out our [full documentation](https://docs.prerender.io)\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2013 Todd Hooper \u0026lt;todd@prerender.io\u0026gt;\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","funding_links":[],"categories":["JavaScript","Web 后端","Tools","others","Applications"],"sub_categories":["React","[`prerender-level-cache`][prerender-level-cache]"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprerender%2Fprerender","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprerender%2Fprerender","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprerender%2Fprerender/lists"}