{"version":"https://jsonfeed.org/version/1.1","title":"Jaryl Chng's Knowledge Base","home_page_url":"https://kb.jarylchng.com","feed_url":"https://kb-jarylchng-com.pages.dev/json/","description":"<p>Welcome to the index page of my knowledge base, if you haven't done so, do visit my website at <a href=\"https://jarylchng.com\" rel=\"noopener noreferrer\" target=\"_blank\">https://jarylchng.com</a>.</p><p>I will mainly use this site to document stuff, most of which will likely be in the public domain.</p>","icon":"https://kb-static.jarylchng.com/kb-jarylchng-com/production/images/channel-c68f1f55f856ab833b4365991609dbec.png","favicon":"https://kb-static.jarylchng.com/kb-jarylchng-com/production/images/favicon-b94914f57599a477f9f72dab6bc71001.png","authors":[{"name":"Jaryl Chng"}],"language":"en-us","items":[{"id":"ybhdO8oR3sV","title":"Javascript - Using chromedp/headless-shell Docker image for Puppeteer","url":"https://kb.jarylchng.com/i/javascript-using-chromedpheadless-shell-docker-ybhdO8oR3sV/","content_html":"<p>I had a personal project that made use of an awesome Puppeteer plugin called <a href=\"https://www.npmjs.com/package/puppeteer-extra-plugin-portal\" rel=\"noopener noreferrer\" target=\"_blank\">puppeteer-extra-plugin-portal</a> by <a href=\"https://github.com/claabs/puppeteer-extra-plugin-portal\" rel=\"noopener noreferrer\" target=\"_blank\">claabs</a>. I wanted to create a Docker container that was small and found <a href=\"https://hub.docker.com/r/chromedp/headless-shell\" rel=\"noopener noreferrer\" target=\"_blank\">chromedp/headless-shell</a>.</p><h2>Sources</h2><h3>main.js</h3><pre class=\"ql-syntax\" spellcheck=\"false\">import puppeteer from 'puppeteer';\npuppeteer.launch(\n{\n  headless: true,\n  args: [\n    \"--disable-gpu\",\n    \"--disable-dev-shm-usage\",\n    \"--disable-setuid-sandbox\",\n    \"--no-sandbox\",\n  ],\n}).then(async browser =&gt; {\n    const page = await browser.newPage();\n    // further logic...\n  }\n)\n</pre><blockquote>Not much difference from a regular Puppeteer setup</blockquote><h3>.dockerignore</h3><pre class=\"ql-syntax\" spellcheck=\"false\">.git\n*.log\nnode_modules\nDockerfile\n</pre><blockquote>We don't want node_modules folder especially as it might contain locally downloaded Chromium for development</blockquote><h3>Dockerfile</h3><pre class=\"ql-syntax\" spellcheck=\"false\">FROM chromedp/headless-shell\n\nENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \\\n    PUPPETEER_EXECUTABLE_PATH=/headless-shell/headless-shell\n\nCOPY . /app\nWORKDIR /app\n\nRUN apt-get update &amp;&amp; \\\n    apt-get install -y tini curl &amp;&amp; \\\n    curl -fsSL https://deb.nodesource.com/setup_17.x | bash - &amp;&amp; \\\n    apt-get install -y nodejs &amp;&amp; \\\n    rm -rf /var/lib/apt/lists/* &amp;&amp; \\\n    npm install\n\nENTRYPOINT [\"tini\", \"--\"]\nCMD [\"/usr/bin/node main.js\"]\n</pre><blockquote>PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true is the most important to keep the image small</blockquote><blockquote>chromedp/headless-shell runs Debian and not Alpine for smaller image sadly, hence using apt, I might look into creating an automated build for Alpine images in the future</blockquote>","content_text":"I had a personal project that made use of an awesome Puppeteer plugin called\npuppeteer-extra-plugin-portal by claabs. I wanted to create a Docker container\nthat was small and found chromedp/headless-shell.\n\n\nSOURCES\n\n\nMAIN.JS\n\nimport puppeteer from 'puppeteer';\npuppeteer.launch(\n{\n  headless: true,\n  args: [\n    \"--disable-gpu\",\n    \"--disable-dev-shm-usage\",\n    \"--disable-setuid-sandbox\",\n    \"--no-sandbox\",\n  ],\n}).then(async browser => {\n    const page = await browser.newPage();\n    // further logic...\n  }\n)\n\n\n> Not much difference from a regular Puppeteer setup\n\n\n.DOCKERIGNORE\n\n.git\n*.log\nnode_modules\nDockerfile\n\n\n> We don't want node_modules folder especially as it might contain locally\n> downloaded Chromium for development\n\n\nDOCKERFILE\n\nFROM chromedp/headless-shell\n\nENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \\\n    PUPPETEER_EXECUTABLE_PATH=/headless-shell/headless-shell\n\nCOPY . /app\nWORKDIR /app\n\nRUN apt-get update && \\\n    apt-get install -y tini curl && \\\n    curl -fsSL https://deb.nodesource.com/setup_17.x | bash - && \\\n    apt-get install -y nodejs && \\\n    rm -rf /var/lib/apt/lists/* && \\\n    npm install\n\nENTRYPOINT [\"tini\", \"--\"]\nCMD [\"/usr/bin/node main.js\"]\n\n\n> PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true is the most important to keep the image\n> small\n\n> chromedp/headless-shell runs Debian and not Alpine for smaller image sadly,\n> hence using apt, I might look into creating an automated build for Alpine\n> images in the future","date_published":"2024-04-06T16:23:08.906Z","_microfeed":{"web_url":"https://kb-jarylchng-com.pages.dev/i/javascript-using-chromedpheadless-shell-docker-ybhdO8oR3sV/","json_url":"https://kb-jarylchng-com.pages.dev/i/ybhdO8oR3sV/json/","rss_url":"https://kb-jarylchng-com.pages.dev/i/ybhdO8oR3sV/rss/","guid":"ybhdO8oR3sV","status":"published","itunes:episodeType":"full","date_published_short":"Sat Apr 06 2024","date_published_ms":1712420588906}}],"_microfeed":{"microfeed_version":"0.1.2","base_url":"https://kb-jarylchng-com.pages.dev","categories":[{"name":"Technology"}],"subscribe_methods":[{"name":"RSS","type":"rss","url":"https://kb-jarylchng-com.pages.dev/rss/","image":"https://kb-jarylchng-com.pages.dev/assets/brands/subscribe/rss.png","enabled":true,"editable":false,"id":"sQbXXExV58H"},{"name":"JSON","type":"json","url":"https://kb-jarylchng-com.pages.dev/json/","image":"https://kb-jarylchng-com.pages.dev/assets/brands/subscribe/json.png","enabled":true,"editable":false,"id":"nC8cjLCnOOi"}],"description_text":"Welcome to the index page of my knowledge base, if you haven't done so, do visit\nmy website at https://jarylchng.com.\n\nI will mainly use this site to document stuff, most of which will likely be in\nthe public domain.","copyright":"©2024","itunes:type":"episodic","items_sort_order":"newest_first"}}