Last active
December 17, 2018 16:19
-
-
Save daliborgogic/5951a7380ff8b57464fcd24f6f42eb36 to your computer and use it in GitHub Desktop.
Navigation Timing, Headless Chrome, Docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"] |
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
Navigation Timing
If you send a
GETrequest to e.g./?url=https://daliborgogic.comyou will get back an object:Total time from start to load:
loadEventEnd - fetchStartTime spent constructing the DOM tree:
domComplete - domInteractiveTime consumed preparing the new page:
fetchStart - navigationStartTime spent during redirection:
redirectEnd - redirectStartAppCache time:
unloadEventEnd - unloadEventStartTime spent unloading documents:
domainLookupStart - fetchStartDNS query time:
domainLookupEnd - domainLookupStartTCP connection time:
connectEnd - connectStartTime spent during the request:
responseEnd - requestStartRequest to completion of the DOM loading:
domInteractive - responseEndLoad event time:
loadEventEnd - loadEventStartRender Time:
domComplete - domLoading