Skip to content

Instantly share code, notes, and snippets.

Eric Bidelman ebidel

Block or report user

Report or block ebidel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
ebidel / polymer-perf-bookmarklet.js
Last active Jul 2, 2019
Polymer performance numbers bookmarklet
View polymer-perf-bookmarklet.js
javascript:(function(){(function printStats(){var;firstPaint=loadTimes.firstPaintTime*1000;firstPaintTime=firstPaint-(loadTimes.startLoadTime*1000);'First paint took',firstPaintTime,'ms');'Load took',performance.timing.loadEventStart-performance.timing.navigationStart,'ms');var instances=0;if(parseFloat(Polymer.version)<1){instances=[]'html /deep/ *')).filter(function(el){return el.localName.indexOf('-')!=-1||el.getAttribute('is');}).length;}else{instances=Polymer.telemetry.instanceCount;}'Custom element instances:',instances);var reflectCount=0;if(Polymer.telemetry){'=== Properties set to reflectToAttribute ===');Polymer.telemetry.registrations.forEach(function(el){for(var prop in{if([prop].reflectToAttribute){console.log('.'+prop);reflectCount++;}}});}else{'=== Properties set to reflect ===');Polymer.elements.forEach(function(el){for(var
ebidel / sw_caching_size.js
Last active Jul 1, 2019
Print service worker cache sizes and overall bytes cached.
View sw_caching_size.js
* @author ebidel@ (Eric Bidelman)
* License Apache-2.0
// Prints the bytes cached by service worker. Breaks out each cache
// overall in-memory bytes used by the Cache Storage API for the site.
async function getCacheStoragesAssetTotalSize() {
// Note: opaque (i.e. cross-domain, without CORS) responses in the cache will return a size of 0.
ebidel / fancy-tabs-demo.html
Last active Jun 28, 2019
Fancy tabs web component - shadow dom v1, custom elements v1, full a11y
View fancy-tabs-demo.html
function execPolyfill() {
// CustomElementsV1.min.js v1 polyfill from
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at
The complete set of authors may be found at
ebidel / feature_detect_es_modules.js
Last active Jun 16, 2019
Feature detect ES modules: both static import and dynamic import()
View feature_detect_es_modules.js
Complete feature detection for ES modules. Covers:
1. Static import: import * from './foo.js';
2. Dynamic import(): import('./foo.js').then(module => {...});
Thanks to @_gsathya, @kevincennis, @rauschma, @malyw for the help.
ebidel / unregistered_custom_elements.bookmarklet.js
Last active May 30, 2019
Logs any custom elements on a page that are not registerd (e.g. missing an HTML import)
View unregistered_custom_elements.bookmarklet.js
javascript:(function(){function isUnregisteredCustomElement(el){if(el.constructor==HTMLElement){console.error("Found unregistered custom element:",el);return true;}return false;}function isCustomEl(el){return el.localName.indexOf('-')!=-1||el.getAttribute('is');}var allCustomElements=document.querySelectorAll('html /deep/ *');{return isCustomEl(el);});var foundSome=false;for(var i=0,el;el=allCustomElements[i];++i){if(isUnregisteredCustomElement(el)){foundSome=true;}}if(foundSome){alert('Oops: found one or more unregistered custom elements in use! Check the console.');}else{alert('Good: All custom elements are registered :)');}})();
ebidel / handle_file_upload.php
Created Apr 18, 2012
Uploading files using xhr.send(FormData) to PHP server
View handle_file_upload.php
$fileName = $_FILES['afile']['name'];
$fileType = $_FILES['afile']['type'];
$fileContent = file_get_contents($_FILES['afile']['tmp_name']);
$dataUrl = 'data:' . $fileType . ';base64,' . base64_encode($fileContent);
$json = json_encode(array(
'name' => $fileName,
'type' => $fileType,
'dataUrl' => $dataUrl,
ebidel / app.html
Last active May 14, 2019
Fast Polymer app loading - optimized for first render, progressively enhanced lazy loading
View app.html
<!DOCTYPE html>
body.loading #splash {
opacity: 1;
#splash {
position: absolute;
top: 0;
ebidel / dom-property-watcher.js
Created Sep 12, 2015
DOM property watcher using ES6 proxies.
View dom-property-watcher.js
// Watch accesses/sets on a DOM element property.
function watchPropsOn(el) {
return new Proxy(el, {
get(target, propKey, receiver) {
//return Reflect.get(target, propKey, receiver);
console.log('get', propKey);
return el[propKey];
set(target, propKey, value, receiver) {
console.log('set', propKey, value);
ebidel / download_chrome41.js
Last active May 6, 2019
For when you need to test your site in Google Search (Chrome 41).
View download_chrome41.js
* Copyright 2018 Google Inc. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
ebidel / object-observe-proxy-polyfill.js
Last active May 5, 2019
Object.observe() polyfill using ES6 Proxies (POC)
View object-observe-proxy-polyfill.js
// An `Object.observe()` "polyfill" using ES6 Proxies.
// Current `Object.observe()` polyfills [1] rely on polling
// to watch for property changes. Proxies can do one better by
// observing property changes to an object without the need for
// polling.
// Known limitations of this technique:
// 1. the call signature of `Object.observe()` will return the proxy
// object. The original object needs to be overwritten with this return value.
You can’t perform that action at this time.