Skip to content

Instantly share code, notes, and snippets.

@daliborgogic
Last active December 17, 2018 16:19
Show Gist options
  • Save daliborgogic/5951a7380ff8b57464fcd24f6f42eb36 to your computer and use it in GitHub Desktop.
Save daliborgogic/5951a7380ff8b57464fcd24f6f42eb36 to your computer and use it in GitHub Desktop.
Navigation Timing, Headless Chrome, Docker
FROM node:8.7.0-slim
RUN apt-get update && \
apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 \
libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 \
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 \
ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
RUN npm i puppeteer micro qs
RUN echo "\
const { parse } = require('qs')\n\
const { send } = require('micro')\n\
const puppeteer = require('puppeteer')\n\
module.exports = async (req, res) => {\n\
async function timings (url) {\n\
const browser = await puppeteer.launch({\n\
// ommmmm\n\
args: ['--disable-setuid-sandbox', '--no-sandbox']\n\
})\n\
const page = await browser.newPage()\n\
await page.goto(url)\n\
const t = await page.evaluate(() => {\n\
return window.performance.timing\n\
})\n\
await browser.close()\n\
return t\n\
}\n\
let url = req.url\n\
const index = url.indexOf('?')\n\
if (index !== -1) {\n\
url = url.substr(index + 1)\n\
}\n\
const query = parse(url)\n\
const t = await timings(query.url)\n\
return t\n\
}\n\
" > index.js
CMD ["node_modules/.bin/micro", "index.js"]
@zb010
Copy link

zb010 commented Dec 17, 2018

I really like this project, it's exactly what I need. But somehow I'm only getting empty responses

Run from the server (outside the container:)

curl http://127.0.0.1:32768/?url=https://daliborgogic.com
{}

The container is running at 0.0.0.0:32768->3000/tcp

Do you have some tips to make this running?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment