Browser Dev Tools you wish you'd known about sooner

Todd Halfpenny

  • Hullo
  • Thank you

Todd Halfpenny

  • Mobile Technical Architect @ Caddify
  • Salesforce MVP
  • London Dev Group Leader
  • London's Calling Organiser
  • Founder @ Shirtforce
  • @toddhalfpenny / @toddhalfpenny.com

Agenda

  • Browser Dev Tools - what are they
  • DEMOs
  • Q&A

We're not doing this alone

  • Very excited for Caech Dreamin
  • Great book choice

So... browser developer tools eh?

OK, shall we make a bet?

The console tab

  • Can access a JavaScript environment
  • interact with our page
  • See any output, warnings, errors, etc
  • Let's have a look at

Our LWC

import getContactList from 
  '@salesforce/apex/ContactController.getContactList';

...

async handleLoad() {
	try {

		this.contacts = await getContactList();

	}
}
					
  • Basic

console.time()

import getContactList from 
  '@salesforce/apex/ContactController.getContactList';

...

async handleLoad() {
	try {
		console.time('getContactList');
		this.contacts = await getContactList();
		console.timeEnd('getContactList');
	}
}
					

console.count()

import getContactList from 
  '@salesforce/apex/ContactController.getContactList';

...

async handleLoad() {
	try {
		console.time('getContactList');
		console.count('getContactList calls');
		this.contacts = await getContactList();
		console.timeEnd('getContactList');
	}
}
					
  • Handy if being called from multiple places

console.trace()

import getContactList from 
  '@salesforce/apex/ContactController.getContactList';

...

async handleLoad() {
	try {
		console.time('getContactList');
		console.count('getContactList calls');
		console.trace();
		this.contacts = await getContactList();
		console.timeEnd('getContactList');
	}
}
					

console.table()

import getContactList from 
  '@salesforce/apex/ContactController.getContactList';

...

async handleLoad() {
	try {
		console.time('getContactList');
    ...
		this.contacts = await getContactList();
		console.table(this.contacts);
		console.timeEnd('getContactList');
	}
}
					

Our logs are looking a bit busy now

console.assert()


async handleLoad() {
	try {
    ...
		this.contacts = await getContactList();
		console.assert(
			this.contacts.length > 0,
			'No contacts received'
		);
	}
}
					
  • Fired if the assertion fCan access a JavaScript environmentails
  • Better than writing your own if branch
  • One more line where Other Todd might have an error

Time for a little experiment

 

console.log('Cheer if you see this');
  • Our logs are still busy
  • What about everyone elses?
  • In a wired callback
  • unfiltered the logs

console.log() - with styling


console.log(
	'%c Cheer if you see me!',
	  'color: black;
	   font-weight: bold;
		 background : lightblue;
		 font-size: 2em;
		 padding: 1em 1em 1em 120px;
		 background-image: url(data:image/...'
);
					

console.group()/groupCollapsed()

async handleLoad() {
	console.groupCollapsed('Apex Imperative Method');
	try {
		console.time('getContactList');
    ...
		this.contacts = await getContactList();
		console.timeEnd('getContactList');
	} ...
	console.groupEnd()
	console.table(this.contacts);
}
					
  • Can be collapsed or expanded by defaul

Interacting with our output

  • copy() - can copy any output like this

Network Requests,

and a dip into Sources

Breakpoints & Logpoints... d'uh!

  • Logpoints - log wihout updating your code

sf deploy start

sf deploy start

Let's have a look at the Elements tab

  • Good for quickly trying UI out

We can increase accesibility too

So, in summary

  • There is a LOT to the dev tools
  • Very handy
  • They are always improving

Thank you

Any questions?