Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Zeunert mattzeunert

View GitHub Profile
View lighthouse-user-flow.js
const puppeteer = require('puppeteer');
const { startFlow } = require('lighthouse/lighthouse-core/fraggle-rock/api.js');
const fs = require("fs");
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
const flow = await startFlow(page, {
name: 'Go to homepage',
@mattzeunert
mattzeunert / github-search.js
Created Nov 6, 2021
Chrome DevTools User Flow Recording for GitHub Search
View github-search.js
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
async function waitForSelectors(selectors, frame) {
for (const selector of selectors) {
try {
return await waitForSelector(selector, frame);
View debugbear-helper-functions.js
var waitFor = async function waitFor(conditionFn, { timeout = 15000, checkInterval = 25, debugString = null, } = {}) {
if (typeof conditionFn !== "function") {
throw Error("waitFor condition argument isn't a function. Did you mean waitForElement?");
}
if (!debugString) {
debugString = conditionFn.toString();
}
let startedAt = new Date();
let conditionResult = await conditionFn();
while (!conditionResult) {
View debounce.js
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
View throttle.js
function throttle (callback, limit) {
var wait = false;
return function () {
if (!wait) {
callback.apply(null, arguments);
wait = true;
setTimeout(function () {
wait = false;
}, limit);
}
View sw.js
self.addEventListener("install", async e => {
caches.open("v1").then(function (cache) {
return cache.addAll(["/app", "/app.css"]);
});
});
self.addEventListener("fetch", event => {
event.respondWith(
caches.match(event.request).then(cachedResponse => {
return cachedResponse || fetch(event.request);