Skip to content

Instantly share code, notes, and snippets.

View vigneshshanmugam's full-sized avatar
🏠
remote

Vignesh Shanmugam vigneshshanmugam

🏠
remote
View GitHub Profile
@vigneshshanmugam
vigneshshanmugam / full-events.txt
Last active April 27, 2023 03:16
Network Protocol events `pw:protocol*`
pw:protocol SEND ► {"id":1,"method":"Browser.getVersion"}"""`
pw:protocol ◀ RECV {"id":1,"result":{"protocolVersion":"1.3","product":"HeadlessChrome/112.0.5615.29","revision":"@8a59304c62e066962363d2fd8edd8e7b459c42bd","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/112.0.5615.29 Safari/537.36","jsVersion":"11.2.214.7"}}"""`
pw:protocol SEND ► {"id":2,"method":"Target.setAutoAttach","params":{"autoAttach":true,"waitForDebuggerOnStart":true,"flatten":true}}"""
pw:protocol ◀ RECV {"id":2,"result":{}}"""`
pw:protocol SEND ► {"id":3,"method":"Target.attachToBrowserTarget"}"""`

It is recommended to run Synthetics tests using the official Heartbeat docker image which contains all the required dependencies and also the chomium browser which is required for running tests.

Prerequisites:
  • Have Node.js installed on the system which comes along with Node Package Manager(NPM).

For running Synthetics outside of docker environment, we need the follow the below steps.

  1. Install playwright chromium NPM library which will install the necessary playwright dependency and also download the
@vigneshshanmugam
vigneshshanmugam / profiler-snippet.js
Last active February 17, 2020 22:05
Profiler snippet
(async()=>{let t=1,e=[];const n=new PerformanceObserver(n=>{const r=n.getEntries();for(const n of r)e.push({id:`${t}`,type:n.entryType,name:n.name,start:Math.round(n.startTime),end:Math.round(n.startTime+n.duration),duration:Math.round(n.duration)}),t++});n.observe({type:"longtask",buffered:!0});const r=await performance.profile({categories:["js"],sampleInterval:1,sampleBufferSize:Number.MAX_SAFE_INTEGER});async function o(){n.disconnect();const t=function(t){const n={};for(const r of t.samples){const o=Math.round(r.timestamp);for(const a of e){const{start:e,name:c,type:i,id:u,end:f,duration:d}=a;if(o>=e&&o<=f){n[u]||(n[u]={name:c,type:i,start:e,end:f,duration:d,culprits:[]});const a=s(t,r.stackId);n[u].culprits.push({time:o,stackId:r.stackId,stack:a})}}}return function(t,e){Object.keys(t).forEach(n=>{const{culprits:r,start:o,end:a}=t[n],s=[];let i=o;for(let t=0,n=1;n<r.length+1;t++,n++){let o=r[t],u=r[n];for(;u&&u.stackId===o.stackId;)n++,o=r[++t],u=r[n];const f=n===r.length,d=f?o.time-i+(a-o.time):o.time-i;
@vigneshshanmugam
vigneshshanmugam / profiler.js
Last active February 17, 2020 21:58
JS Sampling Profiler
const profiler = await performance.profile({
categories: ["js"],
sampleInterval: 10
});
const trace = await profiler.stop();
// Example trace looks something like this
{
"frames": [
{
"column": 4,
@vigneshshanmugam
vigneshshanmugam / capture-longtasks.js
Last active February 17, 2020 21:10
Observing longtasks using performance observer
const observer = new PerformanceObserver(function(list) {
const entries = list.getEntries();
// An example entry looks something like this
const exampleEntry = {
name: "same-origin-descendant",
entryType: "longtask",
startTime: 1023.40999995591,
duration: 187.19000002602115,
attribution: [
{
@vigneshshanmugam
vigneshshanmugam / ispromise.js
Last active April 18, 2018 19:32
Test if a given function is promise
// From graphql-js, https://github.com/graphql/graphql-js/blob/499a75939f70c4863d44149371d6a99d57ff7c35/src/jsutils/isPromise.js#L18
function isPromiseWithBoxing(value) {
return Boolean(value && typeof value.then === "function");
}
// Tailor source - https://github.com/zalando/tailor/blob/0d930d30d6ea3936985ecf3714a3d93fa755b628/src/pipe.js#L53
function isPromiseWithoutBoxing(value) {
return (
value != null &&
typeof value === "object" &&
typeof value.then === "function"
'use strict';
(function(Pipe, perf) {
if (Pipe === undefined) {
return;
}
if (!('mark' in perf && 'measure' in perf)) {
return;
}
var fragmentMap = Object.create(null);
@vigneshshanmugam
vigneshshanmugam / results.md
Last active March 17, 2020 14:52
Object.keys benchmark in v8

Before

Code

const types = {};
const typeSymbols = t => {
  // don't recompute
  if (Object.keys(types).length < 1) {
    t.TYPES.forEach(type => {
      types[type] = Symbol.for(type);

Keybase proof

I hereby claim:

  • I am vigneshshanmugam on github.
  • I am vigneshh (https://keybase.io/vigneshh) on keybase.
  • I have a public key ASDHqWA__CuARSBArXZPUCAKHYbFuzu60qTjPjVcYvBHHgo

To claim this, I am signing this object: