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 / 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 / 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;

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 / 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"}"""`