### Run Rendertron Locally Source: https://github.com/render-examples/rendertron/blob/master/README.md Starts the Rendertron server locally after building the project. Requires a local Chrome installation. ```bash npm run start ``` -------------------------------- ### Install Rendertron Source: https://github.com/render-examples/rendertron/blob/master/README.md Installs Rendertron globally using npm. This command is used to get the Rendertron CLI tool. ```bash npm install -g rendertron ``` -------------------------------- ### Rendertron Installation and Running Source: https://github.com/render-examples/rendertron/blob/master/README.md Provides instructions for installing Rendertron and running it locally, including building the project and deploying it. ```bash # Install dependencies npm install # Build the project npm run build # Run locally node ./dist/server.js # Deploy to Render (example command, actual deployment may vary) # git push origin master # (Follow Render's deployment process) ``` -------------------------------- ### Run Rendertron CLI Source: https://github.com/render-examples/rendertron/blob/master/README.md Starts the Rendertron service locally using the command-line interface. Assumes Chrome is installed on the machine. ```bash rendertron ``` -------------------------------- ### Rendertron Documentation Source: https://github.com/render-examples/rendertron/blob/master/src/index.html Official documentation for Rendertron, covering its features, installation, and usage for rendering web pages and taking screenshots. ```APIDOC Rendertron: Description: A tool for rendering web pages and taking screenshots. Features: - Render web pages - Take screenshots - Serialize content - Mobile rendering Documentation: - [_insert_drive_file_ View documentation](https://github.com/GoogleChrome/rendertron) ``` -------------------------------- ### Install Rendertron Middleware Source: https://github.com/render-examples/rendertron/blob/master/middleware/README.md Installs the necessary packages, express and rendertron-middleware, for integrating Rendertron into an Express application. ```sh $ npm install --save express rendertron-middleware ``` -------------------------------- ### Build Rendertron Project Source: https://github.com/render-examples/rendertron/blob/master/README.md Clones the Rendertron repository, navigates into the directory, and installs project dependencies, followed by building the project. ```bash git clone https://github.com/GoogleChrome/rendertron.git cd rendertron npm install npm run build ``` -------------------------------- ### Basic Rendertron Rendering Example Source: https://github.com/render-examples/rendertron/blob/master/test-resources/explicit-render-event.html This JavaScript snippet demonstrates a basic Rendertron rendering scenario. It sets a flag `renderComplete` to false, then simulates asynchronous content loading by updating the body's text content after a 5-second delay and setting `renderComplete` to true. A second timeout is included to show content that should not be reached. ```javascript window.renderComplete = false; setTimeout(() => { document.body.textContent = 'async loaded'; window.renderComplete = true; }, 5000); setTimeout(() => { document.body.textContent = 'should not be reached'; }, 11000); ``` -------------------------------- ### Rendertron Configuration Source: https://github.com/render-examples/rendertron/blob/master/README.md Example of a `config.json` file for configuring Rendertron. It includes options for caching, timeouts, port, and rendering resolution. ```json { "datastoreCache": true, "timeout": 20000, "port": 8080, "width": 1200, "height": 1200 } ``` -------------------------------- ### Encoding Query Parameters Example Source: https://github.com/render-examples/rendertron/blob/master/README.md Demonstrates how to correctly encode query parameters when passing them in a URL to Rendertron, ensuring proper parsing of special characters. ```javascript const myURLWithParams = "http://my.domain/?page=home"; const encodedURL = encodeURIComponent(myURLWithParams); console.log(encodedURL); // Output: http%3A%2F%2Fmy.domain%2F%3Fpage%3Dhome // Example usage with Rendertron: // https://rendertron.onrender.com/render/http%3A%2F%2Fmy.domain%2F%3Fpage%3Dhome ``` -------------------------------- ### Rendertron Styling Source: https://github.com/render-examples/rendertron/blob/master/src/index.html CSS styles for the Rendertron interface, including body layout, headings, search bar, progress bar, buttons, and responsive design adjustments. ```css body { background: black; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: 'Orbitron', sans-serif; margin: 0; min-height: calc(100vh - 40px); padding: 20px 0; } h1 { font-size: 60px; color: white; border-bottom: 1px solid #99f3ff; margin: 64px 32px; } #search-bar { min-width: 300px; width: calc(100% - 40px); max-width: 664px; position: relative; box-sizing: border-box; } input[type=url] { width: 100%; padding: 30px; box-sizing: border-box; border: none; font-size: 24px; background: black; border-radius: 10px; border: 2px solid #99f3ff; color: white; font-family: 'Orbitron', sans-serif; text-align: center; } progress-bar { --progress-bar-color: #99f3ff; height: 10px; position: absolute; margin-top: -10px; border-radius: 0 0 10px 10px; } #options { margin-top: 32px; display: flex; flex-wrap: wrap; max-width: 800px; justify-content: center; } #options>* { margin: 32px; } #options button { display: block; width: 300px; height: 300px; border: 1px solid #99f3ff; color: white; background: none; display: flex; flex-direction: column; font-size: 18px; font-family: 'Orbitron', sans-serif; align-items: center; justify-content: center; cursor: pointer; } .loading { box-shadow: #99f3ff 0px 0px 7px 4px; animation: pulse 1s infinite alternate cubic-bezier(0.4, 0, 0.2, 1); } .error { border-color: #FF9999 !important; } @keyframes pulse { from { filter: blur(0px); transform: none; } to { filter: blur(1px); transform: scale(1.05); } } #options button i { font-size: 96px; } #options button span { margin-top: 24px; max-width: 200px; line-height: 24px; } a { text-decoration: none; color: inherit; } :focus, #url:focus, #options button:hover { transition: 100ms box-shadow cubic-bezier(0, 0, 0.2, 1); box-shadow: #99f3ff 0px 0px 7px 4px; } @media (max-width: 500px) { h1 { font-size: 40px; } } ``` -------------------------------- ### Rendertron URL Encoding Source: https://github.com/render-examples/rendertron/blob/master/src/index.html Encodes a full URL for use with Rendertron. It preserves the origin, pathname, search parameters, and hash. ```javascript function encodeUrl(fullUrl) { var url = new URL(fullUrl); return url.origin + url.pathname + encodeURIComponent(url.search) + encodeURIComponent(url.hash); } ``` -------------------------------- ### Rendertron Error Handling Source: https://github.com/render-examples/rendertron/blob/master/src/index.html Handles the case where the URL input is empty by adding an 'error' class to the URL element. ```javascript function onEmptyUrl() { url.classList.add('error'); } ``` -------------------------------- ### Custom Element Definition Source: https://github.com/render-examples/rendertron/blob/master/test-resources/shadow-dom-polyfill-all.html Defines a custom HTML element 'my-element' that attaches a shadow DOM with specific content. This demonstrates basic Web Component creation. ```javascript class MyElement extends HTMLElement { constructor() { super(); const shadowRoot = this.attachShadow({mode: 'open'}); shadowRoot.innerHTML = 'shadow-root' + '-text'; } } customElements.define('my-element', MyElement); ``` -------------------------------- ### Rendertron Screenshot Capture Source: https://github.com/render-examples/rendertron/blob/master/src/index.html Takes a screenshot of a web page using Rendertron. It ensures the URL has a protocol, adds a loading indicator, and navigates to the Rendertron screenshot service with specified dimensions. ```javascript function takeScreenshot(element) { if (!url.value) { onEmptyUrl(); return; } var httpRegex = /(http(s?))\:\/\//gi; if (!httpRegex.test(url.value)) { url.value = 'https://' + url.value; } element.classList.add('loading'); document.querySelector('progress-bar').removeAttribute('hidden'); window.location.href += `screenshot/${encodeUrl(url.value)}?width=${window.innerWidth}&height=${window.innerHeight}`; } ``` -------------------------------- ### Custom Element Definition Source: https://github.com/render-examples/rendertron/blob/master/test-resources/shadow-dom-polyfill-loader.html Defines a custom HTML element 'my-element' that attaches a shadow DOM with specific content. This demonstrates basic Web Component creation. ```javascript class MyElement extends HTMLElement { constructor() { super(); const shadowRoot = this.attachShadow({mode: 'open'}); shadowRoot.innerHTML = 'shadow-root' + '-text'; } } customElements.define('my-element', MyElement); ``` -------------------------------- ### Custom Element Definition Source: https://github.com/render-examples/rendertron/blob/master/test-resources/shadow-dom-no-polyfill.html Defines a custom HTML element 'my-element' that attaches a shadow DOM with specific content. This demonstrates basic Web Component creation. ```javascript class MyElement extends HTMLElement { constructor() { super(); const shadowRoot = this.attachShadow({mode: 'open'}); shadowRoot.innerHTML = 'shadow-root' + '-text'; } } customElements.define('my-element', MyElement); ``` -------------------------------- ### Custom HTML Element Definition Source: https://github.com/render-examples/rendertron/blob/master/test-resources/custom-element.html Defines a custom HTML element named 'custom-element' that renders a simple div with text. This demonstrates basic web component creation. ```javascript class MyElement extends HTMLElement { constructor() { super(); this.innerHTML = '